Class: OpenapiBlocks::Spec::Components

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_blocks/spec/components.rb

Overview

rubocop:disable Style/Documentation

Constant Summary collapse

INPUT_IGNORED_PROPERTIES =
%w[id created_at updated_at deleted_at].freeze

Instance Method Summary collapse

Constructor Details

#initialize(openapi_classes) ⇒ Components

Returns a new instance of Components.



11
12
13
# File 'lib/openapi_blocks/spec/components.rb', line 11

def initialize(openapi_classes)
  @openapi_classes = openapi_classes
end

Instance Method Details

#buildObject

rubocop:disable Metrics/AbcSize



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/openapi_blocks/spec/components.rb', line 15

def build # rubocop:disable Metrics/AbcSize
  schemas = @openapi_classes.each_with_object({}) do |klass, hash|
    schema_name = klass.model.name
    extractor   = Schema::Extractor.new(klass)
    validator   = Schema::Validator.new(klass.model)

    schema              = extractor.extract
    schema[:properties] = merge_validations(schema[:properties], validator.extract)

    hash[schema_name]            = schema
    hash["#{schema_name}Input"]  = build_input(schema, klass)
  end

  { schemas: schemas }
end