Class: Docit::Builders::RequestBodyBuilder
- Inherits:
-
Object
- Object
- Docit::Builders::RequestBodyBuilder
- Defined in:
- lib/docit/builders/request_body_builder.rb
Overview
Builds the schema for a request body, including properties, required fields, and schema references.
Instance Attribute Summary collapse
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#required ⇒ Object
readonly
Returns the value of attribute required.
-
#schema_ref ⇒ Object
readonly
Returns the value of attribute schema_ref.
Instance Method Summary collapse
-
#initialize(required: false, content_type: "application/json") ⇒ RequestBodyBuilder
constructor
A new instance of RequestBodyBuilder.
- #property(name, type:, required: false, format: nil, example: nil, enum: nil, description: nil, items: nil, **opts, &block) ⇒ Object
- #required_properties ⇒ Object
- #schema(ref:) ⇒ Object
Constructor Details
#initialize(required: false, content_type: "application/json") ⇒ RequestBodyBuilder
Returns a new instance of RequestBodyBuilder.
10 11 12 13 14 15 |
# File 'lib/docit/builders/request_body_builder.rb', line 10 def initialize(required: false, content_type: "application/json") @required = required @content_type = content_type @properties = [] @schema_ref = nil end |
Instance Attribute Details
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
8 9 10 |
# File 'lib/docit/builders/request_body_builder.rb', line 8 def content_type @content_type end |
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
8 9 10 |
# File 'lib/docit/builders/request_body_builder.rb', line 8 def properties @properties end |
#required ⇒ Object (readonly)
Returns the value of attribute required.
8 9 10 |
# File 'lib/docit/builders/request_body_builder.rb', line 8 def required @required end |
#schema_ref ⇒ Object (readonly)
Returns the value of attribute schema_ref.
8 9 10 |
# File 'lib/docit/builders/request_body_builder.rb', line 8 def schema_ref @schema_ref end |
Instance Method Details
#property(name, type:, required: false, format: nil, example: nil, enum: nil, description: nil, items: nil, **opts, &block) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/docit/builders/request_body_builder.rb', line 21 def property(name, type:, required: false, format: nil, example: nil, enum: nil, description: nil, items: nil, **opts, &block) prop = { name: name, type: type, required: required } 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(required: @required, content_type: @content_type) nested.instance_eval(&block) prop[:children] = nested.properties end @properties << prop end |
#required_properties ⇒ Object
40 41 42 |
# File 'lib/docit/builders/request_body_builder.rb', line 40 def required_properties @properties.select { |prop| prop[:required] }.map { |prop| prop[:name].to_s } end |
#schema(ref:) ⇒ Object
17 18 19 |
# File 'lib/docit/builders/request_body_builder.rb', line 17 def schema(ref:) @schema_ref = ref.to_sym end |