jsapi 0.1.1 → 0.2.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/controller/error_result.rb +1 -2
- data/lib/jsapi/controller/methods.rb +16 -19
- data/lib/jsapi/controller/parameters.rb +7 -8
- data/lib/jsapi/controller/parameters_invalid.rb +1 -2
- data/lib/jsapi/controller/response.rb +4 -2
- data/lib/jsapi/dsl/callbacks.rb +1 -1
- data/lib/jsapi/dsl/definitions.rb +3 -3
- data/lib/jsapi/dsl/error.rb +3 -5
- data/lib/jsapi/dsl/examples.rb +1 -1
- data/lib/jsapi/dsl/openapi/callback.rb +1 -1
- data/lib/jsapi/dsl/openapi/root.rb +115 -1
- data/lib/jsapi/dsl/operation.rb +50 -11
- data/lib/jsapi/dsl/parameter.rb +19 -0
- data/lib/jsapi/dsl/request_body.rb +12 -0
- data/lib/jsapi/dsl/response.rb +19 -0
- data/lib/jsapi/dsl/schema.rb +140 -14
- data/lib/jsapi/json/array.rb +2 -3
- data/lib/jsapi/json/null.rb +2 -2
- data/lib/jsapi/json/object.rb +1 -1
- data/lib/jsapi/json/string.rb +25 -11
- data/lib/jsapi/json/value.rb +5 -5
- data/lib/jsapi/meta/attributes/type_caster.rb +3 -2
- data/lib/jsapi/meta/base.rb +3 -2
- data/lib/jsapi/meta/base_reference.rb +3 -2
- data/lib/jsapi/meta/definitions.rb +2 -1
- data/lib/jsapi/meta/example/model.rb +1 -2
- data/lib/jsapi/meta/example/reference.rb +0 -1
- data/lib/jsapi/meta/invalid_argument_error.rb +1 -0
- data/lib/jsapi/meta/openapi/callback/model.rb +1 -1
- data/lib/jsapi/meta/openapi/root.rb +8 -8
- data/lib/jsapi/meta/openapi/security_scheme/oauth2.rb +1 -2
- data/lib/jsapi/meta/openapi/security_scheme/open_id_connect.rb +2 -3
- data/lib/jsapi/meta/openapi/security_scheme.rb +2 -2
- data/lib/jsapi/meta/openapi/version.rb +3 -0
- data/lib/jsapi/meta/operation.rb +15 -24
- data/lib/jsapi/meta/parameter/model.rb +5 -3
- data/lib/jsapi/meta/parameter/reference.rb +3 -4
- data/lib/jsapi/meta/property.rb +6 -5
- data/lib/jsapi/meta/request_body/model.rb +2 -1
- data/lib/jsapi/meta/rescue_handler.rb +7 -0
- data/lib/jsapi/meta/response/model.rb +2 -1
- data/lib/jsapi/meta/schema/array.rb +9 -1
- data/lib/jsapi/meta/schema/base.rb +7 -9
- data/lib/jsapi/meta/schema/object.rb +1 -1
- data/lib/jsapi/meta/schema/reference.rb +1 -5
- data/lib/jsapi/meta/schema/string.rb +2 -6
- data/lib/jsapi/meta/schema/validation/maximum.rb +6 -2
- data/lib/jsapi/meta/schema/validation/minimum.rb +6 -2
- data/lib/jsapi/meta/schema/validation/multiple_of.rb +3 -1
- data/lib/jsapi/meta/schema.rb +1 -3
- data/lib/jsapi/model/base.rb +2 -2
- data/lib/jsapi/model/errors.rb +3 -4
- data/lib/jsapi/model/naming.rb +3 -4
- data/lib/jsapi/model/validations.rb +2 -2
- data/lib/jsapi/version.rb +5 -3
- metadata +5 -3
data/lib/jsapi/dsl/schema.rb
CHANGED
@@ -5,24 +5,82 @@ module Jsapi
|
|
5
5
|
# Used to specify details of a schema.
|
6
6
|
class Schema < Node
|
7
7
|
|
8
|
-
# Includes all of the properties from +schemas+. Each argument must
|
9
|
-
#
|
10
|
-
# Definitions#schema.
|
8
|
+
# Includes all of the properties from +schemas+. Each argument must be the name of
|
9
|
+
# a schema defined by ClassMethods#api_schema or Definitions#schema.
|
11
10
|
def all_of(*schemas)
|
12
|
-
schemas.each { |schema| _meta_model.add_all_of({
|
11
|
+
schemas.each { |schema| _meta_model.add_all_of({ ref: schema }) }
|
13
12
|
end
|
14
13
|
|
15
|
-
|
14
|
+
##
|
15
|
+
# :method: conversion
|
16
|
+
# :args: method_or_proc
|
17
|
+
# Specifies the method or +Proc+ to convert values by.
|
18
|
+
#
|
19
|
+
# conversion :upcase
|
20
|
+
#
|
21
|
+
# conversion ->(value) { value.upcase }
|
22
|
+
#
|
23
|
+
# Raises an error if type is other than <code>"integer"</code>,
|
24
|
+
# <code>"number"</code> or <code>"string"</code>.
|
25
|
+
|
26
|
+
##
|
27
|
+
# :method: default
|
28
|
+
# :args: value
|
29
|
+
# Specifies the default value.
|
30
|
+
|
31
|
+
##
|
32
|
+
# :method: deprecated
|
33
|
+
# :args: arg
|
34
|
+
# Specifies whether or not the schema is deprecated.
|
35
|
+
#
|
36
|
+
# deprecated true
|
37
|
+
|
38
|
+
##
|
39
|
+
# :method: description
|
40
|
+
# :args: arg
|
41
|
+
# Specifies the description of the schema.
|
42
|
+
|
43
|
+
##
|
44
|
+
# :method: enum
|
45
|
+
# :args: values
|
46
|
+
# Specifies the allowed values.
|
47
|
+
#
|
48
|
+
# enum %w[foo bar]
|
49
|
+
|
50
|
+
## :method: external_docs
|
51
|
+
## :args: **keywords, &blocks
|
52
|
+
# Specifies the external documentation.
|
53
|
+
#
|
54
|
+
# See Meta::Schema::Base#external_docs for further information.
|
55
|
+
|
56
|
+
# Adds a sample matching the schema.
|
57
|
+
#
|
58
|
+
# example 'foo'
|
16
59
|
def example(example)
|
17
60
|
_meta_model.add_example(example)
|
18
61
|
end
|
19
62
|
|
20
|
-
|
21
|
-
|
63
|
+
##
|
64
|
+
# :method: existence
|
65
|
+
# :args: level
|
66
|
+
# Specifies the level of existence.
|
67
|
+
#
|
68
|
+
# existence :allow_nil
|
69
|
+
#
|
70
|
+
# See Meta::Schema::Base#existence for further information.
|
71
|
+
|
72
|
+
# Specifies the format of a string.
|
73
|
+
#
|
74
|
+
# format 'date-time'
|
75
|
+
#
|
76
|
+
# Raises an Error if type is other than <code>"string"</code>.
|
77
|
+
#
|
78
|
+
# See Meta::Schema::String#format for further information.
|
79
|
+
def format(format)
|
22
80
|
_keyword(:format, format)
|
23
81
|
end
|
24
82
|
|
25
|
-
#
|
83
|
+
# Defines the kind of items that can be contained in an array.
|
26
84
|
#
|
27
85
|
# items do
|
28
86
|
# property 'foo', type: 'string'
|
@@ -38,7 +96,57 @@ module Jsapi
|
|
38
96
|
Schema.new(_meta_model.items, &block) if block
|
39
97
|
end
|
40
98
|
|
41
|
-
|
99
|
+
##
|
100
|
+
# :method: max_items
|
101
|
+
# :args: value
|
102
|
+
# Specifies the maximum length of an array.
|
103
|
+
#
|
104
|
+
# Raises an Error if type is other than <code>"array"</code>.
|
105
|
+
|
106
|
+
##
|
107
|
+
# :method: max_length
|
108
|
+
# :args: value
|
109
|
+
# Specifies the maximum length of a string.
|
110
|
+
#
|
111
|
+
# Raises an Error if type is other than <code>"string"</code>.
|
112
|
+
|
113
|
+
##
|
114
|
+
# :method: maximum
|
115
|
+
# :args: value_or_keywords
|
116
|
+
# Specifies the maximum value of an integer or a number.
|
117
|
+
#
|
118
|
+
# maximum 9
|
119
|
+
#
|
120
|
+
# maximum value: 10, exclusive: true
|
121
|
+
#
|
122
|
+
# Raises an Error if type is other than <code>"integer"</code> or <code>"number"</code>.
|
123
|
+
|
124
|
+
##
|
125
|
+
# :method: min_items
|
126
|
+
# :args: value
|
127
|
+
# Specifies the minimum length of an array.
|
128
|
+
#
|
129
|
+
# Raises an Error if type is other than <code>"array"</code>.
|
130
|
+
|
131
|
+
##
|
132
|
+
# :method: min_length
|
133
|
+
# :args: min_length
|
134
|
+
# Specifies the minimum length of a string.
|
135
|
+
#
|
136
|
+
# Raises an Error if type is other than <code>"string"</code>.
|
137
|
+
|
138
|
+
##
|
139
|
+
# :method: minimum
|
140
|
+
# :args: value_or_keywords
|
141
|
+
# Specifies the minimum value of an integer or a number.
|
142
|
+
#
|
143
|
+
# minimum 1
|
144
|
+
#
|
145
|
+
# minimum value: 0, exclusive: true
|
146
|
+
#
|
147
|
+
# Raises an Error if type is other than <code>"integer"</code> or <code>"number"</code>.
|
148
|
+
|
149
|
+
# Defines the model class to access nested object parameters by.
|
42
150
|
#
|
43
151
|
# model Foo do
|
44
152
|
# def bar
|
@@ -46,9 +154,8 @@ module Jsapi
|
|
46
154
|
# end
|
47
155
|
# end
|
48
156
|
#
|
49
|
-
# +klass+ can be any subclass of Model::Base. If block is given, an
|
50
|
-
#
|
51
|
-
# Model::Base.
|
157
|
+
# +klass+ can be any subclass of Model::Base. If block is given, an anonymous class
|
158
|
+
# is created that inherits either from +klass+ or Model::Base.
|
52
159
|
#
|
53
160
|
# Raises an Error if type is other than <code>"object"</code>.
|
54
161
|
def model(klass = nil, &block)
|
@@ -63,11 +170,25 @@ module Jsapi
|
|
63
170
|
_meta_model.model = klass
|
64
171
|
end
|
65
172
|
|
66
|
-
|
173
|
+
##
|
174
|
+
# :method: multiple_of
|
175
|
+
# :args: value
|
176
|
+
# Specifies the value an integer or a number must be a multiple of.
|
177
|
+
#
|
178
|
+
# Raises an Error if type is other than <code>"integer"</code> or <code>"number"</code>.
|
179
|
+
|
180
|
+
##
|
181
|
+
# :method: pattern
|
182
|
+
# :args: regex
|
183
|
+
# Specifies the regular expression a string must match.
|
184
|
+
#
|
185
|
+
# Raises an Error if type is other than <code>"string"</code>.
|
186
|
+
|
187
|
+
# Adds a property.
|
67
188
|
#
|
68
189
|
# property 'foo', type: 'string'
|
69
190
|
#
|
70
|
-
# property 'foo' do
|
191
|
+
# property 'foo', type: 'object' do
|
71
192
|
# property 'bar', type: 'string'
|
72
193
|
# end
|
73
194
|
#
|
@@ -82,6 +203,11 @@ module Jsapi
|
|
82
203
|
Schema.new(property_model, &block) if block
|
83
204
|
end
|
84
205
|
end
|
206
|
+
|
207
|
+
##
|
208
|
+
# :method: title
|
209
|
+
# :args: arg
|
210
|
+
# Specifies the title of the schema.
|
85
211
|
end
|
86
212
|
end
|
87
213
|
end
|
data/lib/jsapi/json/array.rb
CHANGED
@@ -11,7 +11,7 @@ module Jsapi
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
# Returns
|
14
|
+
# Returns true if it contains no elements, false otherwise.
|
15
15
|
def empty?
|
16
16
|
@elements.empty?
|
17
17
|
end
|
@@ -20,8 +20,7 @@ module Jsapi
|
|
20
20
|
"#<#{self.class.name} [#{@elements.map(&:inspect).join(', ')}]>"
|
21
21
|
end
|
22
22
|
|
23
|
-
|
24
|
-
def validate(errors)
|
23
|
+
def validate(errors) # :nodoc:
|
25
24
|
return false unless super
|
26
25
|
|
27
26
|
@elements.map { |element| element.validate(errors) }.all?
|
data/lib/jsapi/json/null.rb
CHANGED
@@ -5,7 +5,7 @@ module Jsapi
|
|
5
5
|
# Represents +null+.
|
6
6
|
class Null < Value
|
7
7
|
|
8
|
-
# Returns
|
8
|
+
# Returns true.
|
9
9
|
def empty?
|
10
10
|
true
|
11
11
|
end
|
@@ -14,7 +14,7 @@ module Jsapi
|
|
14
14
|
"#<#{self.class}>"
|
15
15
|
end
|
16
16
|
|
17
|
-
# Returns
|
17
|
+
# Returns true.
|
18
18
|
def null?
|
19
19
|
true
|
20
20
|
end
|
data/lib/jsapi/json/object.rb
CHANGED
data/lib/jsapi/json/string.rb
CHANGED
@@ -8,22 +8,36 @@ module Jsapi
|
|
8
8
|
|
9
9
|
def initialize(value, schema)
|
10
10
|
super(schema)
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
11
|
+
|
12
|
+
@value =
|
13
|
+
begin
|
14
|
+
case schema.format
|
15
|
+
when 'date'
|
16
|
+
value.to_date
|
17
|
+
when 'date-time'
|
18
|
+
value.to_datetime
|
19
|
+
when 'duration'
|
20
|
+
ActiveSupport::Duration.parse(value)
|
21
|
+
else
|
22
|
+
value.to_s
|
23
|
+
end
|
24
|
+
rescue StandardError => e
|
25
|
+
@error = e
|
26
|
+
value
|
19
27
|
end
|
20
|
-
)
|
28
|
+
@value = schema.convert(@value) unless defined? @error
|
21
29
|
end
|
22
30
|
|
23
|
-
|
24
|
-
def empty?
|
31
|
+
def empty? # :nodoc:
|
25
32
|
value.blank?
|
26
33
|
end
|
34
|
+
|
35
|
+
def validate(errors) # :nodoc:
|
36
|
+
return super unless defined? @error
|
37
|
+
|
38
|
+
errors.add(:base, :invalid)
|
39
|
+
false
|
40
|
+
end
|
27
41
|
end
|
28
42
|
end
|
29
43
|
end
|
data/lib/jsapi/json/value.rb
CHANGED
@@ -14,7 +14,7 @@ module Jsapi
|
|
14
14
|
end
|
15
15
|
|
16
16
|
# Used by #validate to test whether or not it is empty.
|
17
|
-
# Returns
|
17
|
+
# Returns false by default.
|
18
18
|
def empty?
|
19
19
|
false
|
20
20
|
end
|
@@ -23,14 +23,14 @@ module Jsapi
|
|
23
23
|
"#<#{self.class} #{value.inspect}>"
|
24
24
|
end
|
25
25
|
|
26
|
-
# Used by #validate to test whether or not it is
|
27
|
-
# Returns
|
26
|
+
# Used by #validate to test whether or not it is null.
|
27
|
+
# Returns false by default.
|
28
28
|
def null?
|
29
29
|
false
|
30
30
|
end
|
31
31
|
|
32
|
-
# Validates it against #schema. Returns
|
33
|
-
#
|
32
|
+
# Validates it against #schema. Returns true if it is valid, false otherwise.
|
33
|
+
# Detected errors are added to +errors+.
|
34
34
|
def validate(errors)
|
35
35
|
unless schema.existence.reach?(self)
|
36
36
|
errors.add(:base, :blank)
|
@@ -34,8 +34,9 @@ module Jsapi
|
|
34
34
|
@name = name
|
35
35
|
end
|
36
36
|
|
37
|
-
# Casts +value+.
|
38
|
-
#
|
37
|
+
# Casts +value+.
|
38
|
+
#
|
39
|
+
# Raises an InvalidArgumentError if the (casted) value is invalid.
|
39
40
|
def cast(value)
|
40
41
|
casted_value = @caster.call(value)
|
41
42
|
return casted_value unless @values&.exclude?(casted_value)
|
data/lib/jsapi/meta/base.rb
CHANGED
@@ -6,8 +6,9 @@ module Jsapi
|
|
6
6
|
class Base
|
7
7
|
extend Attributes::ClassMethods
|
8
8
|
|
9
|
-
# Creates a new meta model.
|
10
|
-
#
|
9
|
+
# Creates a new meta model.
|
10
|
+
#
|
11
|
+
# Raises an +ArgumentError+ if at least one keyword is not supported.
|
11
12
|
def initialize(keywords = {})
|
12
13
|
keywords.each do |key, value|
|
13
14
|
if respond_to?(method = "#{key}=")
|
@@ -2,14 +2,15 @@
|
|
2
2
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
|
+
# The base reference class.
|
5
6
|
class BaseReference < Base
|
6
7
|
##
|
7
8
|
# :attr: ref
|
8
9
|
# The name of the referred object.
|
9
10
|
attribute :ref, String
|
10
11
|
|
11
|
-
# Returns the name of the method to be invoked to look up the referred
|
12
|
-
#
|
12
|
+
# Returns the name of the method to be invoked to look up the referred object
|
13
|
+
# in a Definitions instance.
|
13
14
|
def self.lookup_method_name
|
14
15
|
@lookup_method_name ||=
|
15
16
|
name.delete_suffix('::Reference').demodulize.underscore
|
@@ -168,7 +168,8 @@ module Jsapi
|
|
168
168
|
private
|
169
169
|
|
170
170
|
def default_operation_name
|
171
|
-
@default_operation_name ||=
|
171
|
+
@default_operation_name ||=
|
172
|
+
@owner.to_s.demodulize.delete_suffix('Controller').underscore
|
172
173
|
end
|
173
174
|
|
174
175
|
def default_path
|
@@ -11,8 +11,7 @@ module Jsapi
|
|
11
11
|
|
12
12
|
##
|
13
13
|
# :attr: external
|
14
|
-
# If true, +value+ is interpreted as a URI pointing to an external
|
15
|
-
# sample value.
|
14
|
+
# If true, +value+ is interpreted as a URI pointing to an external sample value.
|
16
15
|
attribute :external, values: [true, false]
|
17
16
|
|
18
17
|
##
|
@@ -7,7 +7,7 @@ module Jsapi
|
|
7
7
|
class Root < Base
|
8
8
|
##
|
9
9
|
# :attr: callbacks
|
10
|
-
# The reusable Callback objects. Applies to \OpenAPI 3.
|
10
|
+
# The reusable Callback objects. Applies to \OpenAPI 3.0 and higher.
|
11
11
|
attribute :callbacks, { String => Callback }
|
12
12
|
|
13
13
|
##
|
@@ -41,7 +41,7 @@ module Jsapi
|
|
41
41
|
|
42
42
|
##
|
43
43
|
# :attr: links
|
44
|
-
# The reusable Link objects. Applies to \OpenAPI 3.
|
44
|
+
# The reusable Link objects. Applies to \OpenAPI 3.0 and higher.
|
45
45
|
attribute :links, { String => Link }
|
46
46
|
|
47
47
|
##
|
@@ -55,8 +55,7 @@ module Jsapi
|
|
55
55
|
|
56
56
|
##
|
57
57
|
# :attr: schemes
|
58
|
-
# The array of transfer protocols supported by the API. Possible
|
59
|
-
# values are:
|
58
|
+
# The array of transfer protocols supported by the API. Possible values are:
|
60
59
|
#
|
61
60
|
# - <code>"http"</code>
|
62
61
|
# - <code>"https"</code>
|
@@ -80,7 +79,7 @@ module Jsapi
|
|
80
79
|
|
81
80
|
##
|
82
81
|
# :attr: servers
|
83
|
-
# The array of Server objects. Applies to \OpenAPI 3.
|
82
|
+
# The array of Server objects. Applies to \OpenAPI 3.0 and higher.
|
84
83
|
attribute :servers, [Server]
|
85
84
|
|
86
85
|
##
|
@@ -97,12 +96,13 @@ module Jsapi
|
|
97
96
|
end
|
98
97
|
|
99
98
|
if version.major == 2
|
99
|
+
uri = servers&.first&.then { |server| URI(server.url) }
|
100
100
|
{
|
101
101
|
swagger: '2.0',
|
102
102
|
info: info&.to_openapi,
|
103
|
-
host: host,
|
104
|
-
basePath: base_path,
|
105
|
-
schemes: schemes,
|
103
|
+
host: host || uri&.hostname,
|
104
|
+
basePath: base_path || uri&.path,
|
105
|
+
schemes: schemes || uri&.scheme&.then { |scheme| [scheme] },
|
106
106
|
consumes: consumed_mime_types,
|
107
107
|
produces: produced_mime_types,
|
108
108
|
securityDefinitions: security_schemes,
|
@@ -16,8 +16,7 @@ module Jsapi
|
|
16
16
|
# - <code>"password"</code>
|
17
17
|
#
|
18
18
|
# Values are OAuthFlow objects.
|
19
|
-
attribute :oauth_flows,
|
20
|
-
{ String => OAuthFlow },
|
19
|
+
attribute :oauth_flows, { String => OAuthFlow },
|
21
20
|
keys: %w[authorization_code client_credentials implicit password]
|
22
21
|
|
23
22
|
# Returns a hash representing the security scheme object.
|
@@ -6,9 +6,8 @@ module Jsapi
|
|
6
6
|
module SecurityScheme
|
7
7
|
# Represents a security scheme based on OpenID Connect.
|
8
8
|
#
|
9
|
-
# OpenID Connect was introduced with \OpenAPI 3.0. Thus, a security
|
10
|
-
#
|
11
|
-
# document.
|
9
|
+
# OpenID Connect was introduced with \OpenAPI 3.0. Thus, a security scheme of
|
10
|
+
# this class is skipped when generating an \OpenAPI 2.0 document.
|
12
11
|
class OpenIDConnect < Base
|
13
12
|
##
|
14
13
|
# :attr: open_id_connect_url
|
@@ -30,11 +30,11 @@ module Jsapi
|
|
30
30
|
APIKey.new(keywords)
|
31
31
|
when 'basic' # OpenAPI 2.0
|
32
32
|
HTTP.new(keywords.merge(scheme: 'basic'))
|
33
|
-
when 'http' # OpenAPI 3.
|
33
|
+
when 'http' # OpenAPI 3.0 and higher
|
34
34
|
HTTP.new(keywords)
|
35
35
|
when 'oauth2'
|
36
36
|
OAuth2.new(keywords)
|
37
|
-
when 'open_id_connect' # OpenAPI 3.
|
37
|
+
when 'open_id_connect' # OpenAPI 3.0 and higher
|
38
38
|
OpenIDConnect.new(keywords)
|
39
39
|
else
|
40
40
|
raise InvalidArgumentError.new(
|
data/lib/jsapi/meta/operation.rb
CHANGED
@@ -5,13 +5,12 @@ module Jsapi
|
|
5
5
|
class Operation < Base
|
6
6
|
##
|
7
7
|
# :attr: callbacks
|
8
|
-
# The optional callbacks. Applies to \OpenAPI 3.
|
8
|
+
# The optional callbacks. Applies to \OpenAPI 3.0 and higher.
|
9
9
|
attribute :callbacks, { String => OpenAPI::Callback }
|
10
10
|
|
11
11
|
##
|
12
12
|
# :attr: consumed_mime_types
|
13
|
-
# The MIME types consumed by the operation.
|
14
|
-
# Applies to \OpenAPI 2.0 only.
|
13
|
+
# The MIME types consumed by the operation. Applies to \OpenAPI 2.0 only.
|
15
14
|
attribute :consumed_mime_types, [String]
|
16
15
|
|
17
16
|
alias :consumes :consumed_mime_types
|
@@ -25,12 +24,12 @@ module Jsapi
|
|
25
24
|
|
26
25
|
##
|
27
26
|
# :attr: description
|
28
|
-
# The
|
27
|
+
# The description of the operation.
|
29
28
|
attribute :description, String
|
30
29
|
|
31
30
|
##
|
32
31
|
# :attr: external_docs
|
33
|
-
# The
|
32
|
+
# The OpenAPI::ExternalDocumentation object.
|
34
33
|
attribute :external_docs, OpenAPI::ExternalDocumentation
|
35
34
|
|
36
35
|
##
|
@@ -46,14 +45,12 @@ module Jsapi
|
|
46
45
|
# - <code>"put"</code>
|
47
46
|
#
|
48
47
|
# The default HTTP verb is <code>"get"</code>.
|
49
|
-
attribute :method,
|
50
|
-
values: %w[delete get head options patch post put],
|
51
|
-
default: 'get'
|
48
|
+
attribute :method, values: %w[delete get head options patch post put], default: 'get'
|
52
49
|
|
53
50
|
##
|
54
51
|
# :attr: model
|
55
|
-
# The model class to access top-level parameters by. The default
|
56
|
-
#
|
52
|
+
# The model class to access top-level parameters by. The default model class
|
53
|
+
# is Model::Base.
|
57
54
|
attribute :model, Class, default: Model::Base
|
58
55
|
|
59
56
|
##
|
@@ -64,9 +61,7 @@ module Jsapi
|
|
64
61
|
##
|
65
62
|
# :attr: parameters
|
66
63
|
# The parameters of the operation.
|
67
|
-
attribute :parameters, { String => Parameter },
|
68
|
-
default: {},
|
69
|
-
writer: false
|
64
|
+
attribute :parameters, { String => Parameter }, default: {}, writer: false
|
70
65
|
|
71
66
|
##
|
72
67
|
# :attr: path
|
@@ -75,8 +70,7 @@ module Jsapi
|
|
75
70
|
|
76
71
|
##
|
77
72
|
# :attr: consumed_mime_types
|
78
|
-
# The MIME types produced by the operation.
|
79
|
-
# Applies to \OpenAPI 2.0 only.
|
73
|
+
# The MIME types produced by the operation. Applies to \OpenAPI 2.0 only.
|
80
74
|
attribute :produced_mime_types, [String]
|
81
75
|
|
82
76
|
alias :produces :produced_mime_types
|
@@ -85,20 +79,17 @@ module Jsapi
|
|
85
79
|
|
86
80
|
##
|
87
81
|
# :attr: request_body
|
88
|
-
# The
|
82
|
+
# The request body of the operation.
|
89
83
|
attribute :request_body, RequestBody
|
90
84
|
|
91
85
|
##
|
92
86
|
# :attr: responses
|
93
87
|
# The responses of the operation.
|
94
|
-
attribute :responses, { String => Response },
|
95
|
-
default: {},
|
96
|
-
default_key: 'default'
|
88
|
+
attribute :responses, { String => Response }, default: {}, default_key: 'default'
|
97
89
|
|
98
90
|
##
|
99
91
|
# :attr: schemes
|
100
|
-
# The transfer protocols supported by the operation. Possible
|
101
|
-
# values are:
|
92
|
+
# The transfer protocols supported by the operation. Possible values are:
|
102
93
|
#
|
103
94
|
# - <code>"http"</code>
|
104
95
|
# - <code>"https"</code>
|
@@ -117,17 +108,17 @@ module Jsapi
|
|
117
108
|
|
118
109
|
##
|
119
110
|
# :attr: servers
|
120
|
-
# The OpenAPI::Server objects. Applies to \OpenAPI 3.
|
111
|
+
# The OpenAPI::Server objects. Applies to \OpenAPI 3.0 and higher.
|
121
112
|
attribute :servers, [OpenAPI::Server]
|
122
113
|
|
123
114
|
##
|
124
115
|
# :attr: summary
|
125
|
-
# The
|
116
|
+
# The short summary of the operation.
|
126
117
|
attribute :summary, String
|
127
118
|
|
128
119
|
##
|
129
120
|
# :attr: tags
|
130
|
-
# The tags used to group operations in an \OpenAPI document.
|
121
|
+
# The tags. Tags are used to group operations in an \OpenAPI document.
|
131
122
|
attribute :tags, [String]
|
132
123
|
|
133
124
|
def initialize(name = nil, keywords = {})
|
@@ -11,12 +11,12 @@ module Jsapi
|
|
11
11
|
|
12
12
|
##
|
13
13
|
# :attr: description
|
14
|
-
# The
|
14
|
+
# The description of the parameter.
|
15
15
|
attribute :description, String
|
16
16
|
|
17
17
|
##
|
18
18
|
# :attr_reader: examples
|
19
|
-
# The
|
19
|
+
# The examples.
|
20
20
|
attribute :examples, { String => Example }, default_key: 'default'
|
21
21
|
|
22
22
|
##
|
@@ -47,12 +47,14 @@ module Jsapi
|
|
47
47
|
def initialize(name, keywords = {})
|
48
48
|
raise ArgumentError, "parameter name can't be blank" if name.blank?
|
49
49
|
|
50
|
+
@name = name.to_s
|
51
|
+
|
50
52
|
keywords = keywords.dup
|
51
53
|
super(keywords.extract!(:deprecated, :description, :examples, :in))
|
52
54
|
|
53
55
|
add_example(value: keywords.delete(:example)) if keywords.key?(:example)
|
56
|
+
keywords[:ref] = keywords.delete(:schema) if keywords.key?(:schema)
|
54
57
|
|
55
|
-
@name = name.to_s
|
56
58
|
@schema = Schema.new(keywords)
|
57
59
|
end
|
58
60
|
|