Class: Dry::Doc::Schema

Inherits:
Object
  • Object
show all
Defined in:
lib/dry/doc/schema.rb

Defined Under Namespace

Classes: Field

Constant Summary collapse

Nullable =
:"x-nullable"
T =
::Dry::Doc::Value::Types

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass) ⇒ Schema

Returns a new instance of Schema.



100
101
102
# File 'lib/dry/doc/schema.rb', line 100

def initialize klass
  @klass, @properties = klass, {}
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



98
99
100
# File 'lib/dry/doc/schema.rb', line 98

def klass
  @klass
end

Instance Method Details

#as_jsonObject



110
111
112
113
114
115
# File 'lib/dry/doc/schema.rb', line 110

def as_json
  { 
    type: :object,
    properties: @properties.transform_values(&:as_json)
  }
end

#register(name, type, description:) ⇒ Object



104
105
106
107
108
# File 'lib/dry/doc/schema.rb', line 104

def register name, type, description:
  @properties[name] = Field.new \
    type:        type,
    description: description
end