jsapi 0.9.1 → 1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/jsapi/dsl/definitions.rb +1 -1
- data/lib/jsapi/dsl/operation.rb +20 -0
- data/lib/jsapi/dsl/schema.rb +12 -2
- data/lib/jsapi/meta/callback/{model.rb → base.rb} +4 -6
- data/lib/jsapi/meta/callback/reference.rb +2 -6
- data/lib/jsapi/meta/callback.rb +3 -3
- data/lib/jsapi/meta/contact.rb +2 -2
- data/lib/jsapi/meta/defaults.rb +1 -1
- data/lib/jsapi/meta/definitions.rb +10 -8
- data/lib/jsapi/meta/example/{model.rb → base.rb} +5 -5
- data/lib/jsapi/meta/example/reference.rb +2 -6
- data/lib/jsapi/meta/example.rb +3 -3
- data/lib/jsapi/meta/external_documentation.rb +2 -2
- data/lib/jsapi/meta/header/{model.rb → base.rb} +3 -3
- data/lib/jsapi/meta/header/reference.rb +2 -6
- data/lib/jsapi/meta/header.rb +3 -3
- data/lib/jsapi/meta/info.rb +15 -7
- data/lib/jsapi/meta/license.rb +28 -5
- data/lib/jsapi/meta/link/{model.rb → base.rb} +2 -2
- data/lib/jsapi/meta/link/reference.rb +2 -6
- data/lib/jsapi/meta/link.rb +3 -3
- data/lib/jsapi/meta/{base → model}/attributes.rb +15 -18
- data/lib/jsapi/meta/{base/model.rb → model/base.rb} +2 -2
- data/lib/jsapi/meta/model/reference.rb +72 -0
- data/lib/jsapi/meta/{base → model}/type_caster.rb +1 -1
- data/lib/jsapi/meta/model.rb +6 -0
- data/lib/jsapi/meta/oauth_flow.rb +2 -2
- data/lib/jsapi/meta/openapi/extensions.rb +9 -25
- data/lib/jsapi/meta/openapi/version.rb +11 -0
- data/lib/jsapi/meta/openapi.rb +10 -0
- data/lib/jsapi/meta/operation.rb +16 -18
- data/lib/jsapi/meta/parameter/{model.rb → base.rb} +86 -69
- data/lib/jsapi/meta/parameter/reference.rb +4 -9
- data/lib/jsapi/meta/parameter.rb +3 -4
- data/lib/jsapi/meta/property.rb +7 -6
- data/lib/jsapi/meta/request_body/{model.rb → base.rb} +11 -9
- data/lib/jsapi/meta/request_body/reference.rb +2 -6
- data/lib/jsapi/meta/request_body.rb +3 -3
- data/lib/jsapi/meta/rescue_handler.rb +1 -1
- data/lib/jsapi/meta/response/{model.rb → base.rb} +3 -3
- data/lib/jsapi/meta/response/reference.rb +2 -9
- data/lib/jsapi/meta/response.rb +3 -3
- data/lib/jsapi/meta/schema/additional_properties.rb +2 -2
- data/lib/jsapi/meta/schema/array.rb +3 -5
- data/lib/jsapi/meta/schema/base.rb +10 -12
- data/lib/jsapi/meta/schema/conversion.rb +2 -2
- data/lib/jsapi/meta/schema/discriminator.rb +1 -1
- data/lib/jsapi/meta/schema/numeric.rb +3 -5
- data/lib/jsapi/meta/schema/object.rb +3 -5
- data/lib/jsapi/meta/schema/reference.rb +6 -6
- data/lib/jsapi/meta/schema/string.rb +3 -5
- data/lib/jsapi/meta/security_requirement.rb +3 -3
- data/lib/jsapi/meta/security_scheme/base.rb +1 -1
- data/lib/jsapi/meta/server.rb +2 -2
- data/lib/jsapi/meta/server_variable.rb +2 -2
- data/lib/jsapi/meta/tag.rb +2 -2
- data/lib/jsapi/meta.rb +1 -1
- data/lib/jsapi/version.rb +1 -1
- metadata +14 -15
- data/lib/jsapi/meta/base/reference.rb +0 -35
- data/lib/jsapi/meta/base.rb +0 -6
- data/lib/jsapi/meta/parameter/to_openapi.rb +0 -13
@@ -0,0 +1,72 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Jsapi
|
4
|
+
module Meta
|
5
|
+
module Model
|
6
|
+
# The base reference class.
|
7
|
+
class Reference < Base
|
8
|
+
# Derrives the component type from the inner most module name.
|
9
|
+
def self.component_type
|
10
|
+
@component_type ||= name.split('::')[-2].underscore
|
11
|
+
end
|
12
|
+
|
13
|
+
# Derrives the \OpenAPI component type from the inner most module name.
|
14
|
+
def self.openapi_component_type
|
15
|
+
@openapi_component_type ||= name.split('::')[-2].pluralize.camelize(:lower)
|
16
|
+
end
|
17
|
+
|
18
|
+
##
|
19
|
+
# :attr: description
|
20
|
+
# The description to be displayed instead of the description of the referred object.
|
21
|
+
# Applies to \OpenAPI 3.1 and higher.
|
22
|
+
attribute :description, String
|
23
|
+
|
24
|
+
##
|
25
|
+
# :attr: ref
|
26
|
+
# The name of the referred object.
|
27
|
+
attribute :ref, String
|
28
|
+
|
29
|
+
##
|
30
|
+
# :attr: summary
|
31
|
+
# The summary to be displayed instead of the summary of the referred object.
|
32
|
+
# Applies to \OpenAPI 3.1 and higher.
|
33
|
+
attribute :summary, String
|
34
|
+
|
35
|
+
# Returns true.
|
36
|
+
def reference?
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
# Resolves +ref+ by looking up the object with that name in +definitions+.
|
41
|
+
#
|
42
|
+
# Raises a ReferenceError if +ref+ could not be resolved.
|
43
|
+
def resolve(definitions)
|
44
|
+
object = definitions.send("find_#{self.class.component_type}", ref)
|
45
|
+
raise ReferenceError, ref if object.nil?
|
46
|
+
|
47
|
+
object.resolve(definitions)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Returns a hash representing the \OpenAPI reference object.
|
51
|
+
def to_openapi(version, *)
|
52
|
+
version = OpenAPI::Version.from(version)
|
53
|
+
|
54
|
+
{ '$ref': "#/#{openapi_components_path(version)}/#{ref}" }.tap do |result|
|
55
|
+
if version >= OpenAPI::V3_1
|
56
|
+
result[:summary] = summary if summary
|
57
|
+
result[:description] = description if description
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def openapi_components_path(version)
|
65
|
+
component_type = self.class.openapi_component_type
|
66
|
+
|
67
|
+
version.major == 2 ? component_type : "components/#{component_type}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -3,10 +3,10 @@
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
5
|
# Represents an OAuth flow object.
|
6
|
-
class OAuthFlow < Base
|
6
|
+
class OAuthFlow < Model::Base
|
7
7
|
include OpenAPI::Extensions
|
8
8
|
|
9
|
-
class Scope < Base
|
9
|
+
class Scope < Model::Base
|
10
10
|
##
|
11
11
|
# :attr: description
|
12
12
|
# The description of the scope.
|
@@ -4,35 +4,19 @@ module Jsapi
|
|
4
4
|
module Meta
|
5
5
|
module OpenAPI
|
6
6
|
module Extensions
|
7
|
-
|
8
|
-
|
9
|
-
# The \OpenAPI extensions.
|
10
|
-
|
11
|
-
# Adds an \OpenAPI extension.
|
12
|
-
#
|
13
|
-
# Raises an +ArgumentError+ if +name+ is blank.
|
14
|
-
def add_openapi_extension(name, value = nil)
|
15
|
-
raise ArgumentError, "name can't be blank" if name.blank?
|
16
|
-
|
17
|
-
openapi_extensions["x-#{name}".to_sym] = value
|
18
|
-
end
|
19
|
-
|
20
|
-
def openapi_extensions # :nodoc:
|
21
|
-
@openapi_extensions ||= {}
|
22
|
-
end
|
23
|
-
|
24
|
-
def openapi_extensions=(extensions) # :nodoc:
|
25
|
-
@openapi_extensions = {}
|
26
|
-
|
27
|
-
extensions.each do |name, value|
|
28
|
-
add_openapi_extension(name, value)
|
29
|
-
end
|
7
|
+
def self.included(base) # :nodoc:
|
8
|
+
base.attribute :openapi_extensions, { String => String }
|
30
9
|
end
|
31
10
|
|
32
11
|
private
|
33
12
|
|
34
|
-
def with_openapi_extensions(keywords = {})
|
35
|
-
keywords.merge!(
|
13
|
+
def with_openapi_extensions(keywords = {})
|
14
|
+
keywords.merge!(
|
15
|
+
openapi_extensions.transform_keys do |key|
|
16
|
+
"x-#{key}".to_sym
|
17
|
+
end
|
18
|
+
) if openapi_extensions.present?
|
19
|
+
|
36
20
|
keywords.compact!
|
37
21
|
keywords
|
38
22
|
end
|
@@ -4,6 +4,8 @@ module Jsapi
|
|
4
4
|
module Meta
|
5
5
|
module OpenAPI
|
6
6
|
class Version
|
7
|
+
include Comparable
|
8
|
+
|
7
9
|
# Creates an \OpenAPI version from +version+.
|
8
10
|
#
|
9
11
|
# Raises an +ArgumentError+ if +version+ isn`t supported.
|
@@ -35,6 +37,15 @@ module Jsapi
|
|
35
37
|
@minor == other.minor
|
36
38
|
end
|
37
39
|
|
40
|
+
def <=>(other)
|
41
|
+
return unless other.is_a?(Version)
|
42
|
+
|
43
|
+
result = major <=> other.major
|
44
|
+
return result unless result.zero?
|
45
|
+
|
46
|
+
minor <=> other.minor
|
47
|
+
end
|
48
|
+
|
38
49
|
def to_s # :nodoc:
|
39
50
|
"#{major}.#{minor}"
|
40
51
|
end
|
data/lib/jsapi/meta/openapi.rb
CHANGED
data/lib/jsapi/meta/operation.rb
CHANGED
@@ -2,8 +2,8 @@
|
|
2
2
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
|
-
#
|
6
|
-
class Operation < Base
|
5
|
+
# Specifies an API operation.
|
6
|
+
class Operation < Model::Base
|
7
7
|
include OpenAPI::Extensions
|
8
8
|
|
9
9
|
##
|
@@ -43,18 +43,18 @@ module Jsapi
|
|
43
43
|
|
44
44
|
##
|
45
45
|
# :attr: model
|
46
|
-
# The model class to access top-level parameters by
|
47
|
-
attribute :model, Class, default: Model::Base
|
46
|
+
# The model class to access top-level parameters by, Jsapi::Model::Base by default.
|
47
|
+
attribute :model, Class, default: Jsapi::Model::Base
|
48
48
|
|
49
49
|
##
|
50
50
|
# :attr_reader: name
|
51
51
|
# The name of the operation.
|
52
|
-
attribute :name,
|
52
|
+
attribute :name, accessors: %i[reader]
|
53
53
|
|
54
54
|
##
|
55
55
|
# :attr: parameters
|
56
56
|
# The parameters of the operation.
|
57
|
-
attribute :parameters, { String => Parameter }
|
57
|
+
attribute :parameters, { String => Parameter }, accessors: %i[reader writer]
|
58
58
|
|
59
59
|
##
|
60
60
|
# :attr: path
|
@@ -110,8 +110,6 @@ module Jsapi
|
|
110
110
|
super(keywords)
|
111
111
|
end
|
112
112
|
|
113
|
-
undef add_parameter
|
114
|
-
|
115
113
|
def add_parameter(name, keywords = {}) # :nodoc:
|
116
114
|
(@parameters ||= {})[name.to_s] = Parameter.new(name, keywords)
|
117
115
|
end
|
@@ -140,36 +138,36 @@ module Jsapi
|
|
140
138
|
externalDocs: external_docs&.to_openapi,
|
141
139
|
deprecated: deprecated?.presence,
|
142
140
|
security: security_requirements.map(&:to_openapi).presence
|
143
|
-
).tap do |
|
141
|
+
).tap do |result|
|
144
142
|
if version.major == 2
|
145
143
|
if (consumes = consumes(definitions)).present?
|
146
|
-
|
144
|
+
result[:consumes] = [consumes]
|
147
145
|
end
|
148
146
|
if (produces = produces(definitions)).present?
|
149
|
-
|
147
|
+
result[:produces] = produces
|
150
148
|
end
|
151
|
-
|
149
|
+
result[:schemes] = schemes if schemes.present?
|
152
150
|
elsif servers.present?
|
153
|
-
|
151
|
+
result[:servers] = servers.map(&:to_openapi)
|
154
152
|
end
|
155
153
|
# Parameters (and request body)
|
156
|
-
|
154
|
+
result[:parameters] = parameters.values.flat_map do |parameter|
|
157
155
|
parameter.to_openapi_parameters(version, definitions)
|
158
156
|
end
|
159
157
|
if request_body
|
160
158
|
if version.major == 2
|
161
|
-
|
159
|
+
result[:parameters] << request_body.resolve(definitions).to_openapi_parameter
|
162
160
|
else
|
163
|
-
|
161
|
+
result[:request_body] = request_body.to_openapi(version)
|
164
162
|
end
|
165
163
|
end
|
166
164
|
# Responses
|
167
|
-
|
165
|
+
result[:responses] = responses.transform_values do |response|
|
168
166
|
response.to_openapi(version, definitions)
|
169
167
|
end
|
170
168
|
# Callbacks
|
171
169
|
if callbacks.present? && version.major > 2
|
172
|
-
|
170
|
+
result[:callbacks] = callbacks.transform_values do |callback|
|
173
171
|
callback.to_openapi(version, definitions)
|
174
172
|
end
|
175
173
|
end
|
@@ -3,9 +3,8 @@
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
5
|
module Parameter
|
6
|
-
#
|
7
|
-
class
|
8
|
-
include ToOpenAPI
|
6
|
+
# Specifies a parameter.
|
7
|
+
class Base < Model::Base
|
9
8
|
include OpenAPI::Extensions
|
10
9
|
|
11
10
|
delegate_missing_to :schema
|
@@ -39,12 +38,12 @@ module Jsapi
|
|
39
38
|
##
|
40
39
|
# :attr_reader: name
|
41
40
|
# The name of the parameter.
|
42
|
-
attribute :name,
|
41
|
+
attribute :name, accessors: %i[reader]
|
43
42
|
|
44
43
|
##
|
45
44
|
# :attr_reader: schema
|
46
45
|
# The Schema of the parameter.
|
47
|
-
attribute :schema,
|
46
|
+
attribute :schema, accessors: %i[reader]
|
48
47
|
|
49
48
|
# Creates a new parameter.
|
50
49
|
#
|
@@ -63,25 +62,40 @@ module Jsapi
|
|
63
62
|
@schema = Schema.new(keywords)
|
64
63
|
end
|
65
64
|
|
66
|
-
# Returns true if empty values are allowed as specified by \OpenAPI,
|
67
|
-
# false otherwise.
|
65
|
+
# Returns true if empty values are allowed as specified by \OpenAPI, false otherwise.
|
68
66
|
def allow_empty_value?
|
69
|
-
schema.existence <= Existence::ALLOW_EMPTY && self.in
|
67
|
+
schema.existence <= Existence::ALLOW_EMPTY && self.in == 'query'
|
70
68
|
end
|
71
69
|
|
72
|
-
# Returns true if it is required as specified by \JSON \Schema,
|
73
|
-
# false otherwise.
|
70
|
+
# Returns true if it is required as specified by \JSON \Schema, false otherwise.
|
74
71
|
def required?
|
75
72
|
schema.existence > Existence::ALLOW_OMITTED || self.in == 'path'
|
76
73
|
end
|
77
74
|
|
75
|
+
# Returns a hash representing the \OpenAPI parameter object.
|
76
|
+
def to_openapi(version, definitions)
|
77
|
+
version = OpenAPI::Version.from(version)
|
78
|
+
schema = self.schema.resolve(definitions)
|
79
|
+
|
80
|
+
openapi_parameter(
|
81
|
+
name,
|
82
|
+
schema,
|
83
|
+
version,
|
84
|
+
description: description,
|
85
|
+
required: required?,
|
86
|
+
deprecated: deprecated?,
|
87
|
+
allow_empty_value: allow_empty_value?,
|
88
|
+
examples: examples
|
89
|
+
)
|
90
|
+
end
|
91
|
+
|
78
92
|
# Returns an array of hashes representing the \OpenAPI parameter objects.
|
79
93
|
def to_openapi_parameters(version, definitions)
|
80
94
|
version = OpenAPI::Version.from(version)
|
81
95
|
schema = self.schema.resolve(definitions)
|
82
96
|
|
83
97
|
if schema.object?
|
84
|
-
|
98
|
+
explode_parameter(
|
85
99
|
name,
|
86
100
|
schema,
|
87
101
|
version,
|
@@ -90,35 +104,16 @@ module Jsapi
|
|
90
104
|
deprecated: deprecated?
|
91
105
|
)
|
92
106
|
else
|
93
|
-
parameter_name = schema.array? ? "#{name}[]" : name
|
94
107
|
[
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
}.merge(schema.to_openapi(version))
|
105
|
-
else
|
106
|
-
{
|
107
|
-
name: parameter_name,
|
108
|
-
in: self.in,
|
109
|
-
description: description,
|
110
|
-
required: required?.presence,
|
111
|
-
allowEmptyValue: allow_empty_value?.presence,
|
112
|
-
deprecated: deprecated?.presence,
|
113
|
-
schema: schema.to_openapi(version),
|
114
|
-
examples: examples.transform_values(&:to_openapi).presence
|
115
|
-
|
116
|
-
# NOTE: collectionFormat is replaced by style and explode.
|
117
|
-
# The default values for query parameters are:
|
118
|
-
# - style: 'form'
|
119
|
-
# - explode: true
|
120
|
-
}
|
121
|
-
end
|
108
|
+
openapi_parameter(
|
109
|
+
name,
|
110
|
+
schema,
|
111
|
+
version,
|
112
|
+
description: description,
|
113
|
+
required: required?,
|
114
|
+
deprecated: deprecated?,
|
115
|
+
allow_empty_value: allow_empty_value?,
|
116
|
+
examples: examples
|
122
117
|
)
|
123
118
|
]
|
124
119
|
end
|
@@ -126,16 +121,15 @@ module Jsapi
|
|
126
121
|
|
127
122
|
private
|
128
123
|
|
129
|
-
def
|
124
|
+
def explode_parameter(name, schema, version, definitions, required:, deprecated:)
|
130
125
|
schema.resolve_properties(definitions, context: :request).values.flat_map do |property|
|
131
126
|
property_schema = property.schema.resolve(definitions)
|
132
127
|
parameter_name = "#{name}[#{property.name}]"
|
133
|
-
|
134
|
-
|
135
|
-
deprecated = (property.deprecated? || options[:deprecated]).presence
|
128
|
+
required = (required && property.required?).presence
|
129
|
+
deprecated = (deprecated || property.deprecated?).presence
|
136
130
|
|
137
131
|
if property_schema.object?
|
138
|
-
|
132
|
+
explode_parameter(
|
139
133
|
parameter_name,
|
140
134
|
property_schema,
|
141
135
|
version,
|
@@ -144,37 +138,60 @@ module Jsapi
|
|
144
138
|
deprecated: deprecated
|
145
139
|
)
|
146
140
|
else
|
147
|
-
parameter_name = "#{parameter_name}[]" if property_schema.array?
|
148
|
-
description = property_schema.description
|
149
|
-
allow_empty_value = property.schema.existence <= Existence::ALLOW_EMPTY
|
150
141
|
[
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
collectionFormat: ('multi' if property_schema.array?)
|
160
|
-
}.merge(property_schema.to_openapi(version))
|
161
|
-
else
|
162
|
-
{
|
163
|
-
name: parameter_name,
|
164
|
-
in: self.in,
|
165
|
-
description: description,
|
166
|
-
required: required,
|
167
|
-
allowEmptyValue: allow_empty_value.presence,
|
168
|
-
deprecated: deprecated,
|
169
|
-
schema: property_schema.to_openapi(version).except(:deprecated),
|
170
|
-
examples: examples.transform_values(&:to_openapi).presence
|
171
|
-
}
|
172
|
-
end
|
142
|
+
openapi_parameter(
|
143
|
+
parameter_name,
|
144
|
+
property_schema,
|
145
|
+
version,
|
146
|
+
description: property_schema.description,
|
147
|
+
required: required,
|
148
|
+
deprecated: deprecated,
|
149
|
+
allow_empty_value: property.schema.existence <= Existence::ALLOW_EMPTY
|
173
150
|
)
|
174
151
|
]
|
175
152
|
end
|
176
153
|
end
|
177
154
|
end
|
155
|
+
|
156
|
+
def openapi_parameter(name, schema, version,
|
157
|
+
allow_empty_value:,
|
158
|
+
deprecated:,
|
159
|
+
description:,
|
160
|
+
required:,
|
161
|
+
examples: nil)
|
162
|
+
|
163
|
+
name = schema.array? ? "#{name}[]" : name
|
164
|
+
|
165
|
+
with_openapi_extensions(
|
166
|
+
if version.major == 2
|
167
|
+
raise "OpenAPI 2.0 doesn't allow object parameters " \
|
168
|
+
"in #{self.in}" if schema.object?
|
169
|
+
|
170
|
+
{
|
171
|
+
name: name,
|
172
|
+
in: self.in,
|
173
|
+
description: description,
|
174
|
+
required: required.presence,
|
175
|
+
allowEmptyValue: allow_empty_value.presence,
|
176
|
+
collectionFormat: ('multi' if schema.array?)
|
177
|
+
}.merge(schema.to_openapi(version))
|
178
|
+
else
|
179
|
+
{
|
180
|
+
name: name,
|
181
|
+
in: self.in,
|
182
|
+
description: description,
|
183
|
+
required: required.presence,
|
184
|
+
allowEmptyValue: allow_empty_value.presence,
|
185
|
+
deprecated: deprecated.presence,
|
186
|
+
schema: schema.to_openapi(version).except(:deprecated),
|
187
|
+
examples: examples&.transform_values(&:to_openapi).presence
|
188
|
+
|
189
|
+
# NOTE: collectionFormat is replaced by 'style' and 'explode'.
|
190
|
+
# The default values are equal to 'multi'.
|
191
|
+
}
|
192
|
+
end
|
193
|
+
)
|
194
|
+
end
|
178
195
|
end
|
179
196
|
end
|
180
197
|
end
|
@@ -3,12 +3,9 @@
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
5
|
module Parameter
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
# Returns an array of hashes. Each hash represents an \OpenAPI parameter object
|
10
|
-
# if the type of the referred parameter is <code>"object"</code>. Otherwise the
|
11
|
-
# array contains a single hash representing the \OpenAPI reference object.
|
6
|
+
# Refers a reusable parameter.
|
7
|
+
class Reference < Model::Reference
|
8
|
+
# Returns an array of hashes representing the \OpenAPI parameter or reference objects.
|
12
9
|
#
|
13
10
|
# Raises a ReferenceError when the reference could not be resolved.
|
14
11
|
def to_openapi_parameters(version, definitions)
|
@@ -20,9 +17,7 @@ module Jsapi
|
|
20
17
|
parameter.to_openapi_parameters(version, definitions)
|
21
18
|
else
|
22
19
|
# Return an array containing the reference object
|
23
|
-
|
24
|
-
|
25
|
-
[{ '$ref': "#/#{path}/#{ref}" }]
|
20
|
+
[to_openapi(version)]
|
26
21
|
end
|
27
22
|
end
|
28
23
|
end
|
data/lib/jsapi/meta/parameter.rb
CHANGED
@@ -1,18 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'parameter/
|
4
|
-
require_relative 'parameter/model'
|
3
|
+
require_relative 'parameter/base'
|
5
4
|
require_relative 'parameter/reference'
|
6
5
|
|
7
6
|
module Jsapi
|
8
7
|
module Meta
|
9
8
|
module Parameter
|
10
9
|
class << self
|
11
|
-
# Creates a
|
10
|
+
# Creates a Base or Reference.
|
12
11
|
def new(name, keywords = {})
|
13
12
|
return Reference.new(keywords) if keywords.key?(:ref)
|
14
13
|
|
15
|
-
|
14
|
+
Base.new(name, keywords)
|
16
15
|
end
|
17
16
|
end
|
18
17
|
end
|
data/lib/jsapi/meta/property.rb
CHANGED
@@ -2,13 +2,14 @@
|
|
2
2
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
|
-
|
5
|
+
# Specifies a property
|
6
|
+
class Property < Model::Base
|
6
7
|
delegate_missing_to :schema
|
7
8
|
|
8
9
|
##
|
9
10
|
# :attr_reader: name
|
10
11
|
# The name of the property.
|
11
|
-
attribute :name,
|
12
|
+
attribute :name, accessors: %i[reader]
|
12
13
|
|
13
14
|
##
|
14
15
|
# :attr: read_only
|
@@ -17,7 +18,7 @@ module Jsapi
|
|
17
18
|
##
|
18
19
|
# :attr_reader: schema
|
19
20
|
# The Schema of the parameter.
|
20
|
-
attribute :schema,
|
21
|
+
attribute :schema, accessors: %i[reader]
|
21
22
|
|
22
23
|
##
|
23
24
|
# :attr: source
|
@@ -59,9 +60,9 @@ module Jsapi
|
|
59
60
|
def to_openapi(version, *)
|
60
61
|
version = OpenAPI::Version.from(version)
|
61
62
|
|
62
|
-
schema.to_openapi(version).tap do |
|
63
|
-
|
64
|
-
|
63
|
+
schema.to_openapi(version).tap do |result|
|
64
|
+
result[:readOnly] = true if read_only?
|
65
|
+
result[:writeOnly] = true if write_only? && version.major > 2
|
65
66
|
end
|
66
67
|
end
|
67
68
|
end
|
@@ -3,8 +3,8 @@
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
5
|
module RequestBody
|
6
|
-
#
|
7
|
-
class
|
6
|
+
# Specifies a request body.
|
7
|
+
class Base < Model::Base
|
8
8
|
include OpenAPI::Extensions
|
9
9
|
|
10
10
|
delegate_missing_to :schema
|
@@ -27,7 +27,7 @@ module Jsapi
|
|
27
27
|
##
|
28
28
|
# :attr_reader: schema
|
29
29
|
# The Schema of the request body.
|
30
|
-
attribute :schema,
|
30
|
+
attribute :schema, accessors: %i[reader]
|
31
31
|
|
32
32
|
def initialize(keywords = {})
|
33
33
|
keywords = keywords.dup
|
@@ -47,12 +47,14 @@ module Jsapi
|
|
47
47
|
|
48
48
|
# Returns a hash representing the \OpenAPI 2.0 parameter object.
|
49
49
|
def to_openapi_parameter
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
50
|
+
with_openapi_extensions(
|
51
|
+
{
|
52
|
+
name: 'body',
|
53
|
+
in: 'body',
|
54
|
+
description: description,
|
55
|
+
required: required?
|
56
|
+
}.merge(schema.to_openapi(OpenAPI::V2_0))
|
57
|
+
)
|
56
58
|
end
|
57
59
|
|
58
60
|
# Returns a hash representing the \OpenAPI 3.x request body object.
|
@@ -3,12 +3,8 @@
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
5
|
module RequestBody
|
6
|
-
|
7
|
-
|
8
|
-
def to_openapi(*)
|
9
|
-
{ '$ref': "#/components/requestBodies/#{ref}" }
|
10
|
-
end
|
11
|
-
end
|
6
|
+
# Refers a reusable request body.
|
7
|
+
class Reference < Model::Reference; end
|
12
8
|
end
|
13
9
|
end
|
14
10
|
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative 'request_body/
|
3
|
+
require_relative 'request_body/base'
|
4
4
|
require_relative 'request_body/reference'
|
5
5
|
|
6
6
|
module Jsapi
|
7
7
|
module Meta
|
8
8
|
module RequestBody
|
9
9
|
class << self
|
10
|
-
# Creates a
|
10
|
+
# Creates a Base or Reference.
|
11
11
|
def new(keywords = {})
|
12
12
|
return Reference.new(keywords) if keywords.key?(:ref)
|
13
13
|
|
14
|
-
|
14
|
+
Base.new(keywords)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|