Class: Jsapi::Meta::OpenAPI::Root
- Defined in:
- lib/jsapi/meta/openapi/root.rb
Overview
Represents an OpenAPI object.
Instance Method Summary collapse
-
#base_path ⇒ Object
:attr: base_path The base path of the API.
-
#callbacks ⇒ Object
:attr: callbacks The reusable Callback objects.
-
#consumed_mime_types ⇒ Object
(also: #consumes)
:attr: consumes The MIME types the API can consume.
-
#external_docs ⇒ Object
:attr: external_docs The optional ExternalDocumentation object.
-
#host ⇒ Object
:attr: host The host serving the API.
-
#info ⇒ Object
:attr: info The Info object.
-
#links ⇒ Object
:attr: links The reusable Link objects.
-
#produced_mime_types ⇒ Object
(also: #produces)
:attr: produces The MIME types the API can produce.
-
#schemes ⇒ Object
:attr: schemes The array of transfer protocols supported by the API.
-
#security_requirements ⇒ Object
:attr: security_requirements The array of SecurityRequirement objects.
-
#security_schemes ⇒ Object
:attr_reader: security_schemes The security schemes.
-
#servers ⇒ Object
:attr: servers The array of Server objects.
-
#tags ⇒ Object
:attr: tags The array of Tag objects.
-
#to_openapi(version, definitions) ⇒ Object
Returns a hash representing the OpenAPI object.
Methods inherited from Base
#initialize, #inspect, #reference?, #resolve
Methods included from Attributes::ClassMethods
Constructor Details
This class inherits a constructor from Jsapi::Meta::Base
Instance Method Details
#base_path ⇒ Object
:attr: base_path The base path of the API. Applies to OpenAPI 2.0.
16 |
# File 'lib/jsapi/meta/openapi/root.rb', line 16 attribute :base_path, String |
#callbacks ⇒ Object
:attr: callbacks The reusable Callback objects. Applies to OpenAPI 3.x.
11 |
# File 'lib/jsapi/meta/openapi/root.rb', line 11 attribute :callbacks, { String => Callback } |
#consumed_mime_types ⇒ Object Also known as: consumes
:attr: consumes The MIME types the API can consume. Applies to OpenAPI 2.0.
21 |
# File 'lib/jsapi/meta/openapi/root.rb', line 21 attribute :consumed_mime_types, [String] |
#external_docs ⇒ Object
:attr: external_docs The optional ExternalDocumentation object.
30 |
# File 'lib/jsapi/meta/openapi/root.rb', line 30 attribute :external_docs, ExternalDocumentation |
#host ⇒ Object
:attr: host The host serving the API. Applies to OpenAPI 2.0.
35 |
# File 'lib/jsapi/meta/openapi/root.rb', line 35 attribute :host, String |
#info ⇒ Object
:attr: info The Info object.
40 |
# File 'lib/jsapi/meta/openapi/root.rb', line 40 attribute :info, Info |
#links ⇒ Object
:attr: links The reusable Link objects. Applies to OpenAPI 3.x.
45 |
# File 'lib/jsapi/meta/openapi/root.rb', line 45 attribute :links, { String => Link } |
#produced_mime_types ⇒ Object Also known as: produces
:attr: produces The MIME types the API can produce. Applies to OpenAPI 2.0.
50 |
# File 'lib/jsapi/meta/openapi/root.rb', line 50 attribute :produced_mime_types, [String] |
#schemes ⇒ Object
:attr: schemes The array of transfer protocols supported by the API. Possible values are:
-
"http"
-
"https"
-
"ws"
-
"wss"
Applies to OpenAPI 2.0.
67 |
# File 'lib/jsapi/meta/openapi/root.rb', line 67 attribute :schemes, [String], values: %w[http https ws wss] |
#security_requirements ⇒ Object
:attr: security_requirements The array of SecurityRequirement objects.
72 |
# File 'lib/jsapi/meta/openapi/root.rb', line 72 attribute :security_requirements, [SecurityRequirement] |
#security_schemes ⇒ Object
:attr_reader: security_schemes The security schemes.
79 |
# File 'lib/jsapi/meta/openapi/root.rb', line 79 attribute :security_schemes, { String => SecurityScheme } |
#servers ⇒ Object
:attr: servers The array of Server objects. Applies to OpenAPI 3.x.
84 |
# File 'lib/jsapi/meta/openapi/root.rb', line 84 attribute :servers, [Server] |
#tags ⇒ Object
:attr: tags The array of Tag objects.
89 |
# File 'lib/jsapi/meta/openapi/root.rb', line 89 attribute :tags, [Tag] |
#to_openapi(version, definitions) ⇒ Object
Returns a hash representing the OpenAPI object.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/jsapi/meta/openapi/root.rb', line 92 def to_openapi(version, definitions) version = Version.from(version) security_schemes = self.security_schemes&.transform_values do |value| value.to_openapi(version) end if version.major == 2 { swagger: '2.0', info: info&.to_openapi, host: host, basePath: base_path, schemes: schemes, consumes: consumed_mime_types, produces: produced_mime_types, securityDefinitions: security_schemes, security: security_requirements&.map(&:to_openapi), tags: &.map(&:to_openapi), externalDocs: external_docs&.to_openapi } else { openapi: version.minor.zero? ? '3.0.3' : '3.1.0', info: info&.to_openapi, servers: servers&.map(&:to_openapi), components: { callbacks: callbacks&.transform_values do |callback| callback.to_openapi(version, definitions) end, links: links&.transform_values(&:to_openapi), securitySchemes: security_schemes }.compact.presence, security: security_requirements&.map(&:to_openapi), tags: &.map(&:to_openapi), externalDocs: external_docs&.to_openapi } end.compact end |