Sha256: 94c6f008f8b0d5da326d0bb1c742c8329befea595b9b5595c93d546fa42a46ec

Contents?: true

Size: 1.17 KB

Versions: 44

Compression:

Stored size: 1.17 KB

Contents

# frozen_string_literal: true

class ReeSwagger::BuildSerializerSchema
  include Ree::FnDSL

  fn :build_serializer_schema do
    link :get_serializer_definition
  end

  contract(ReeMapper::Mapper, ArrayOf[ReeMapper::FieldsFilter] => Nilor[Hash])
  def call(mapper, fields_filters = [])
    if mapper.type
      return get_serializer_definition(mapper.type, method(:call).to_proc)
    end

    properties = mapper.fields.each_with_object({}) do |(_name, field), acc|
      next unless fields_filters.all? { _1.allow?(field.name) }

      if field.type == mapper
        acc[field.name] = {}
        next
      end

      swagger_field = {}

      field_mapper = field.type

      nested_fields_filters = fields_filters.map { _1.filter_for(field.name) }
      nested_fields_filters += [field.fields_filter]

      swagger_type = call(field_mapper, nested_fields_filters)

      swagger_field.merge!(swagger_type) if swagger_type

      description = field.doc
      swagger_field[:description] = description if description

      swagger_field[:nullable] = true if field.null

      acc[field.name] = swagger_field
    end

    {
      type: 'object',
      properties: properties
    }
  end
end

Version data entries

44 entries across 44 versions & 1 rubygems

Version Path
ree_lib-1.0.93 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb
ree_lib-1.0.92 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb
ree_lib-1.0.91 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb
ree_lib-1.0.90 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb
ree_lib-1.0.89 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb
ree_lib-1.0.88 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb
ree_lib-1.0.87 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb
ree_lib-1.0.86 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb
ree_lib-1.0.85 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb
ree_lib-1.0.84 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb
ree_lib-1.0.83 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb
ree_lib-1.0.82 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb
ree_lib-1.0.81 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb
ree_lib-1.0.80 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb
ree_lib-1.0.79 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb
ree_lib-1.0.78 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb
ree_lib-1.0.77 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb
ree_lib-1.0.76 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb
ree_lib-1.0.75 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb
ree_lib-1.0.74 lib/ree_lib/packages/ree_swagger/package/ree_swagger/functions/build_serializer_schema.rb