Class: Docit::SchemaDefinition
- Inherits:
-
Object
- Object
- Docit::SchemaDefinition
- Defined in:
- lib/docit/schema_definition.rb
Overview
A reusable schema definition that can be referenced via $ref. Defined with define_schema and rendered under components/schemas in the OpenAPI spec.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
Instance Method Summary collapse
-
#initialize(name) ⇒ SchemaDefinition
constructor
A new instance of SchemaDefinition.
- #property(prop_name, type:, format: nil, example: nil, enum: nil, description: nil, items: nil, **opts, &block) ⇒ Object
Constructor Details
#initialize(name) ⇒ SchemaDefinition
Returns a new instance of SchemaDefinition.
10 11 12 13 |
# File 'lib/docit/schema_definition.rb', line 10 def initialize(name) @name = name @properties = [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/docit/schema_definition.rb', line 8 def name @name end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
8 9 10 |
# File 'lib/docit/schema_definition.rb', line 8 def properties @properties end |
Instance Method Details
#property(prop_name, type:, format: nil, example: nil, enum: nil, description: nil, items: nil, **opts, &block) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/docit/schema_definition.rb', line 15 def property(prop_name, type:, format: nil, example: nil, enum: nil, description: nil, items: nil, **opts, &block) prop = { name: prop_name, type: type } prop[:format] = format if format prop[:example] = example if example prop[:enum] = enum if enum prop[:description] = description if description prop[:items] = items if items prop.merge!(opts) if block_given? nested = self.class.new(:"#{@name}_#{prop_name}") nested.instance_eval(&block) prop[:children] = nested.properties end @properties << prop end |