Class: Jsapi::Meta::RequestBody::Model
- Defined in:
- lib/jsapi/meta/request_body/model.rb
Instance Method Summary collapse
-
#description ⇒ Object
:attr: description The optional description of the request body.
-
#examples ⇒ Object
:attr_reader: examples The optional examples.
-
#initialize(keywords = {}) ⇒ Model
constructor
A new instance of Model.
-
#required? ⇒ Boolean
Returns true if the level of existence is greater than or equal to
ALLOW_NIL
, false otherwise. -
#schema ⇒ Object
:attr_reader: schema The Schema of the parameter.
-
#to_openapi(version) ⇒ Object
Returns a hash representing the OpenAPI 3.x request body object.
-
#to_openapi_parameter ⇒ Object
Returns a hash representing the OpenAPI 2.0 parameter object.
Methods inherited from Base
#inspect, #reference?, #resolve
Methods included from Attributes::ClassMethods
Constructor Details
#initialize(keywords = {}) ⇒ Model
Returns a new instance of Model.
24 25 26 27 28 29 30 31 |
# File 'lib/jsapi/meta/request_body/model.rb', line 24 def initialize(keywords = {}) keywords = keywords.dup super(keywords.extract!(:description, :examples)) add_example(value: keywords.delete(:example)) if keywords.key?(:example) @schema = Schema.new(keywords) end |
Instance Method Details
#description ⇒ Object
:attr: description The optional description of the request body.
10 |
# File 'lib/jsapi/meta/request_body/model.rb', line 10 attribute :description, String |
#examples ⇒ Object
:attr_reader: examples The optional examples.
15 |
# File 'lib/jsapi/meta/request_body/model.rb', line 15 attribute :examples, { String => Example }, default_key: 'default' |
#required? ⇒ Boolean
Returns true if the level of existence is greater than or equal to ALLOW_NIL
, false otherwise.
35 36 37 |
# File 'lib/jsapi/meta/request_body/model.rb', line 35 def required? schema.existence >= Existence::ALLOW_NIL end |
#schema ⇒ Object
:attr_reader: schema The Schema of the parameter.
20 |
# File 'lib/jsapi/meta/request_body/model.rb', line 20 attribute :schema, writer: false |
#to_openapi(version) ⇒ Object
Returns a hash representing the OpenAPI 3.x request body object.
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/jsapi/meta/request_body/model.rb', line 50 def to_openapi(version) { description: description, content: { 'application/json' => { schema: schema.to_openapi(version), examples: examples&.transform_values(&:to_openapi) }.compact }, required: required? }.compact end |
#to_openapi_parameter ⇒ Object
Returns a hash representing the OpenAPI 2.0 parameter object.
40 41 42 43 44 45 46 47 |
# File 'lib/jsapi/meta/request_body/model.rb', line 40 def to_openapi_parameter { name: 'body', in: 'body', description: description, required: required? }.merge(schema.to_openapi('2.0')).compact end |