Sha256: db335e271c11753b17e314c8173c25f3f234d283caadc90181f4f0e049c1fcb7

Contents?: true

Size: 1.32 KB

Versions: 31

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

class ReeSwagger::BuildParameters
  include Ree::FnDSL

  fn :build_parameters do
    link :get_caster_definition
    link :build_request_body_schema
    link :wrap, from: :ree_array
  end

  ObjectPathParamError = Class.new(StandardError)
  ArrayPathParamError = Class.new(StandardError)

  contract(ReeMapper::Mapper, ArrayOf[Symbol], Bool => ArrayOf[Hash])
  def call(mapper, path_params, with_query_params)
    mapper.fields.filter_map do |_name, field|
      is_path_param = path_params.include?(field.name)

      next unless is_path_param || with_query_params

      if is_path_param
        if field.type.type.nil?
          raise ObjectPathParamError, "path parameter(#{
            field.name
          }) can not be an object"
        end

        if field.type.type.is_a?(ReeMapper::Array)
          raise ArrayPathParamError, "path parameter(#{
            field.name
          }) can not be an array"
        end
      end

      schema =  {
        name: field.name_as_str,
        in: is_path_param ? 'path' : 'query',
        required: is_path_param || !field.optional,
        schema: build_request_body_schema(field.type, [], wrap(field.fields_filter)) || {}
      }

      schema[:style] = 'deepObject' if field.type.type.nil?
      schema[:nullable] = true if field.null

      schema
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
ree_lib-1.0.124 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.123 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.122 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.121 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.120 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.119 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.118 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.117 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.116 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.115 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.114 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.113 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.112 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.111 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.110 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.109 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.108 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.107 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.106 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.105 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb