Class: Jsapi::Meta::Header::Model
- Inherits:
-
Base::Model
- Object
- Base::Model
- Jsapi::Meta::Header::Model
- Includes:
- OpenAPI::Extensions
- Defined in:
- lib/jsapi/meta/header/model.rb
Overview
Specifies a header object.
Constant Summary
Constants included from Base::Attributes
Base::Attributes::DEFAULT_ARRAY, Base::Attributes::DEFAULT_HASH
Instance Method Summary collapse
-
#collection_format ⇒ Object
:attr: collection_format The collection format of a header whose values are arrays.
-
#deprecated ⇒ Object
:attr: deprecated Specifies whether or not the header is deprecated.
-
#description ⇒ Object
:attr: description The description of the header.
-
#examples ⇒ Object
:attr_reader: examples One or more example values.
-
#initialize(keywords = {}) ⇒ Model
constructor
A new instance of Model.
-
#schema ⇒ Object
:attr_reader: schema The Schema of the header.
-
#to_openapi(version) ⇒ Object
Returns a hash representing the OpenAPI header object.
Methods included from OpenAPI::Extensions
#add_openapi_extension, #openapi_extensions, #openapi_extensions=
Methods inherited from Base::Model
#inspect, #merge!, #reference?, #resolve
Methods included from Base::Attributes
Constructor Details
#initialize(keywords = {}) ⇒ Model
Returns a new instance of Model.
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/jsapi/meta/header/model.rb', line 44 def initialize(keywords = {}) raise ArgumentError, "type can't be object" if keywords[:type] == 'object' keywords = keywords.dup super( keywords.extract!( :collection_format, :deprecated, :description, :examples, :openapi_extensions ) ) add_example(value: keywords.delete(:example)) if keywords.key?(:example) @schema = Schema.new(keywords) end |
Instance Method Details
#collection_format ⇒ Object
:attr: collection_format The collection format of a header whose values are arrays. Possible values are:
-
"csv"
- comma separated values -
"pipes"
- pipe separated values -
"ssv"
- space separated values -
"tsv"
- tab separated values
Applies to OpenAPI 2.0.
22 |
# File 'lib/jsapi/meta/header/model.rb', line 22 attribute :collection_format, values: %w[csv pipes ssv tsv] |
#deprecated ⇒ Object
:attr: deprecated Specifies whether or not the header is deprecated.
27 |
# File 'lib/jsapi/meta/header/model.rb', line 27 attribute :deprecated, values: [true, false] |
#description ⇒ Object
:attr: description The description of the header.
32 |
# File 'lib/jsapi/meta/header/model.rb', line 32 attribute :description, String |
#examples ⇒ Object
:attr_reader: examples One or more example values.
37 |
# File 'lib/jsapi/meta/header/model.rb', line 37 attribute :examples, { String => Example }, default_key: 'default' |
#schema ⇒ Object
:attr_reader: schema The Schema of the header.
42 |
# File 'lib/jsapi/meta/header/model.rb', line 42 attribute :schema, read_only: true |
#to_openapi(version) ⇒ Object
Returns a hash representing the OpenAPI header object.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/jsapi/meta/header/model.rb', line 59 def to_openapi(version, *) version = OpenAPI::Version.from(version) with_openapi_extensions( if version.major == 2 schema.to_openapi(version).merge( collection_format: (collection_format if array?), description: description ) else { description: description, deprecated: deprecated?.presence, schema: schema.to_openapi(version), examples: examples.transform_values(&:to_openapi).presence } end ) end |