Class: Jsapi::Meta::Content
- Inherits:
-
Jsapi::Model::Base
- Object
- Jsapi::Model::Base
- Jsapi::Meta::Content
- Includes:
- OpenAPI::Extensions, Model::Wrappable
- Defined in:
- lib/jsapi/meta/content.rb
Overview
Specifies the content of a request body or response.
Defined Under Namespace
Classes: Wrapper
Instance Method Summary collapse
-
#examples ⇒ Object
:attr: examples The examples.
-
#initialize(keywords = {}) ⇒ Content
constructor
A new instance of Content.
-
#schema ⇒ Object
:attr_reader: schema The Schema of the content.
-
#to_openapi(version, media_type = nil) ⇒ Object
Returns a hash representing the OpenAPI media type object describing the content.
Methods included from OpenAPI::Extensions
Methods inherited from Jsapi::Model::Base
#==, #errors, #inspect, model_name, #respond_to_missing?
Constructor Details
#initialize(keywords = {}) ⇒ Content
Returns a new instance of Content.
29 30 31 32 33 34 35 36 37 |
# File 'lib/jsapi/meta/content.rb', line 29 def initialize(keywords = {}) keywords = keywords.dup super(keywords.extract!(: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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Jsapi::Model::Base
Instance Method Details
#examples ⇒ Object
:attr: examples The examples. Maps example names to Example objects or references.
22 |
# File 'lib/jsapi/meta/content.rb', line 22 attribute :examples, { String => Example }, default_key: 'default' |
#schema ⇒ Object
:attr_reader: schema The Schema of the content.
27 |
# File 'lib/jsapi/meta/content.rb', line 27 attribute :schema, accessors: %i[reader] |
#to_openapi(version, media_type = nil) ⇒ Object
Returns a hash representing the OpenAPI media type object describing the content. Applies to OpenAPI 3.0 and higher.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/jsapi/meta/content.rb', line 41 def to_openapi(version, media_type = nil) version = OpenAPI::Version.from(version) with_openapi_extensions( **if media_type == Media::Type::APPLICATION_JSON_SEQ && schema.array? && version >= OpenAPI::V3_2 { itemSchema: schema.items.to_openapi(version) } else { schema: schema.to_openapi(version) } end, examples: examples.transform_values do |example| example.to_openapi(version) end.presence ) end |