Class: Jsapi::Meta::RequestBody::Base
- Inherits:
-
Model::Base
- Object
- Model::Base
- Jsapi::Meta::RequestBody::Base
- Includes:
- OpenAPI::Extensions
- Defined in:
- lib/jsapi/meta/request_body/base.rb
Overview
Specifies a request body.
Constant Summary
Constants included from Model::Attributes
Model::Attributes::DEFAULT_ARRAY, Model::Attributes::DEFAULT_HASH
Instance Method Summary collapse
-
#content_type ⇒ Object
:attr: content_type The content type.
-
#description ⇒ Object
:attr: description The description of the request body.
-
#examples ⇒ Object
:attr_reader: examples The Example objects.
-
#initialize(keywords = {}) ⇒ Base
constructor
A new instance of Base.
-
#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 request body.
-
#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 included from OpenAPI::Extensions
Methods inherited from Model::Base
#inspect, #merge!, #reference?, #resolve
Methods included from Model::Attributes
Constructor Details
#initialize(keywords = {}) ⇒ Base
Returns a new instance of Base.
32 33 34 35 36 37 38 39 40 |
# File 'lib/jsapi/meta/request_body/base.rb', line 32 def initialize(keywords = {}) keywords = keywords.dup super(keywords.extract!(:content_type, :description, :examples, :openapi_extensions)) add_example(value: keywords.delete(:example)) if keywords.key?(:example) keywords[:ref] = keywords.delete(:schema) if keywords.key?(:schema) @schema = Schema.new(keywords) end |
Instance Method Details
#content_type ⇒ Object
:attr: content_type The content type. "application/json"
by default.
15 |
# File 'lib/jsapi/meta/request_body/base.rb', line 15 attribute :content_type, String, default: 'application/json' |
#description ⇒ Object
:attr: description The description of the request body.
20 |
# File 'lib/jsapi/meta/request_body/base.rb', line 20 attribute :description, String |
#examples ⇒ Object
:attr_reader: examples The Example objects.
25 |
# File 'lib/jsapi/meta/request_body/base.rb', line 25 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.
44 45 46 |
# File 'lib/jsapi/meta/request_body/base.rb', line 44 def required? schema.existence >= Existence::ALLOW_NIL end |
#schema ⇒ Object
:attr_reader: schema The Schema of the request body.
30 |
# File 'lib/jsapi/meta/request_body/base.rb', line 30 attribute :schema, accessors: %i[reader] |
#to_openapi(version) ⇒ Object
Returns a hash representing the OpenAPI 3.x request body object.
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/jsapi/meta/request_body/base.rb', line 61 def to_openapi(version, *) with_openapi_extensions( description: description, content: { content_type => { schema: schema.to_openapi(version), examples: examples.transform_values(&:to_openapi).presence }.compact }, required: required? ) end |
#to_openapi_parameter ⇒ Object
Returns a hash representing the OpenAPI 2.0 parameter object.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/jsapi/meta/request_body/base.rb', line 49 def to_openapi_parameter with_openapi_extensions( { name: 'body', in: 'body', description: description, required: required? }.merge(schema.to_openapi(OpenAPI::V2_0)) ) end |