Sha256: 92812c42f129c50a7cba0c638c89c3c03f1c3b16421570c5091f881d5f156fc4

Contents?: true

Size: 1.26 KB

Versions: 22

Compression:

Stored size: 1.26 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
  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) || {}
      }

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

      schema
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
ree_lib-1.0.21 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.20 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.19 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.18 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.17 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.16 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.15 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.14 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.13 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.12 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.11 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.10 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.9 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.8 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.7 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.6 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.5 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.4 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.3 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb
ree_lib-1.0.2 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_parameters.rb