Class: Docit::Builders::ResponseBuilder
- Inherits:
-
Object
- Object
- Docit::Builders::ResponseBuilder
- Defined in:
- lib/docit/builders/response_builder.rb
Overview
Builds the schema for a single HTTP response, including properties, examples, and schema references.
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#examples ⇒ Object
readonly
Returns the value of attribute examples.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#schema_ref ⇒ Object
readonly
Returns the value of attribute schema_ref.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
- #example(name, value, description: nil) ⇒ Object
-
#initialize(status:, description:) ⇒ ResponseBuilder
constructor
A new instance of ResponseBuilder.
- #property(name, type:, format: nil, example: nil, enum: nil, description: nil, items: nil, **opts, &block) ⇒ Object
- #schema(ref:) ⇒ Object
Constructor Details
#initialize(status:, description:) ⇒ ResponseBuilder
Returns a new instance of ResponseBuilder.
10 11 12 13 14 15 16 |
# File 'lib/docit/builders/response_builder.rb', line 10 def initialize(status:, description:) @status = status @description = description @properties = [] @examples = [] @schema_ref = nil end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
8 9 10 |
# File 'lib/docit/builders/response_builder.rb', line 8 def description @description end |
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
8 9 10 |
# File 'lib/docit/builders/response_builder.rb', line 8 def examples @examples end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
8 9 10 |
# File 'lib/docit/builders/response_builder.rb', line 8 def properties @properties end |
#schema_ref ⇒ Object (readonly)
Returns the value of attribute schema_ref.
8 9 10 |
# File 'lib/docit/builders/response_builder.rb', line 8 def schema_ref @schema_ref end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
8 9 10 |
# File 'lib/docit/builders/response_builder.rb', line 8 def status @status end |
Instance Method Details
#example(name, value, description: nil) ⇒ Object
40 41 42 43 44 |
# File 'lib/docit/builders/response_builder.rb', line 40 def example(name, value, description: nil) ex = { name: name, value: value } ex[:description] = description if description @examples << ex end |
#property(name, type:, format: nil, example: nil, enum: nil, description: nil, items: nil, **opts, &block) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/docit/builders/response_builder.rb', line 22 def property(name, type:, format: nil, example: nil, enum: nil, description: nil, items: nil, **opts, &block) prop = { name: 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(status: @status, description: @description) nested.instance_eval(&block) prop[:children] = nested.properties end @properties << prop end |
#schema(ref:) ⇒ Object
18 19 20 |
# File 'lib/docit/builders/response_builder.rb', line 18 def schema(ref:) @schema_ref = ref.to_sym end |