Sha256: 3db4a6c757702d1d35f6ab6b136006751ed349400cae96bbe0b1f3e261493818

Contents?: true

Size: 1.41 KB

Versions: 11

Compression:

Stored size: 1.41 KB

Contents

module OasParser
  class Property < AbstractAttribute
    raw_keys :description, :type, :format, :minimum, :maximum,
             :example, :default, :items

    attr_accessor :owner, :schema, :raw
    attr_writer :name

    def initialize(owner, schema, name, raw)
      super(name)
      @owner = owner
      @schema = schema
      @raw = raw
    end

    def required
      return true if raw['required']
      return false unless schema['required']
      schema['required'].include? name
    end

    def convert_property_schema_to_properties(schema)
      if schema['allOf']
        schema['properties'] = {}
        schema['allOf'].each do |p|
          schema['properties'].deep_merge!(p['properties'])
        end
        schema.delete('allOf')
      end

      if schema['oneOf']
        schema['oneOf'].map do |subschema|
          subschema['properties'] = convert_property_schema_to_properties(subschema)
          subschema['subschema_property'] = true
          subschema
        end
      elsif schema['subschema_property']
        schema = schema['properties'] if schema['properties']
        schema.map do |definition|
          OasParser::Property.new(self, raw, definition.name, definition.raw)
        end
      else
        schema = schema['properties'] if schema['properties']
        schema.map do |key, definition|
          OasParser::Property.new(self, raw, key, definition)
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
oas_parser-0.25.1 lib/oas_parser/property.rb
oas_parser-0.25.0 lib/oas_parser/property.rb
oas_parser-0.24.0 lib/oas_parser/property.rb
oas_parser-0.23.0 lib/oas_parser/property.rb
oas_parser-0.22.4 lib/oas_parser/property.rb
oas_parser-0.22.2 lib/oas_parser/property.rb
oas_parser-0.22.1 lib/oas_parser/property.rb
oas_parser-0.22.0 lib/oas_parser/property.rb
oas_parser-0.21.1 lib/oas_parser/property.rb
oas_parser-0.21.0 lib/oas_parser/property.rb
oas_parser-0.20.0 lib/oas_parser/property.rb