Sha256: bc24fd5446ec2476ea8e562cb6948a6196cb75aca37cb41d84376f78ac057b62

Contents?: true

Size: 1.2 KB

Versions: 9

Compression:

Stored size: 1.2 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['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

9 entries across 9 versions & 1 rubygems

Version Path
oas_parser-0.19.0 lib/oas_parser/property.rb
oas_parser-0.18.2 lib/oas_parser/property.rb
oas_parser-0.18.1 lib/oas_parser/property.rb
oas_parser-0.18.0 lib/oas_parser/property.rb
oas_parser-0.17.0 lib/oas_parser/property.rb
oas_parser-0.16.0 lib/oas_parser/property.rb
oas_parser-0.15.2 lib/oas_parser/property.rb
oas_parser-0.15.1 lib/oas_parser/property.rb
oas_parser-0.15.0 lib/oas_parser/property.rb