Sha256: f7f63c21cadf9470f99f195a91b6ccc5ed486713f7641c931934f76a17e34064

Contents?: true

Size: 1.37 KB

Versions: 1

Compression:

Stored size: 1.37 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 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

1 entries across 1 versions & 1 rubygems

Version Path
oas_parser-0.25.3 lib/oas_parser/property.rb