jsapi 0.1.1 → 0.1.2
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 +2 -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 +29 -0
- data/lib/jsapi/dsl/request_body.rb +22 -0
- data/lib/jsapi/dsl/response.rb +29 -0
- data/lib/jsapi/dsl/schema.rb +139 -13
- data/lib/jsapi/json/value.rb +2 -2
- 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 +4 -5
- 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 +2 -2
- data/lib/jsapi/meta/parameter/reference.rb +3 -4
- data/lib/jsapi/meta/property.rb +3 -4
- data/lib/jsapi/meta/request_body/model.rb +1 -1
- data/lib/jsapi/meta/rescue_handler.rb +7 -0
- data/lib/jsapi/meta/response/model.rb +1 -1
- data/lib/jsapi/meta/schema/base.rb +7 -9
- data/lib/jsapi/meta/schema/reference.rb +1 -2
- data/lib/jsapi/meta/schema/string.rb +1 -1
- 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/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
11
|
schemas.each { |schema| _meta_model.add_all_of({ schema: 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/value.rb
CHANGED
@@ -29,8 +29,8 @@ module Jsapi
|
|
29
29
|
false
|
30
30
|
end
|
31
31
|
|
32
|
-
# Validates it against #schema. Returns +true+ if it is valid, +false+
|
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
|
##
|
@@ -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
|
##
|
@@ -4,10 +4,9 @@ module Jsapi
|
|
4
4
|
module Meta
|
5
5
|
module Parameter
|
6
6
|
class Reference < BaseReference
|
7
|
-
# Returns an array of hashes. Each element represents an \OpenAPI
|
8
|
-
#
|
9
|
-
#
|
10
|
-
# hash representing the \OpenAPI reference object.
|
7
|
+
# Returns an array of hashes. Each element represents an \OpenAPI parameter object
|
8
|
+
# if the type of the referred parameter is <code>"object"</code>. Otherwise the
|
9
|
+
# array contains a single hash representing the \OpenAPI reference object.
|
11
10
|
#
|
12
11
|
# Raises a ReferenceError if the reference could not be resolved.
|
13
12
|
def to_openapi(version, definitions)
|
data/lib/jsapi/meta/property.rb
CHANGED
@@ -19,8 +19,7 @@ module Jsapi
|
|
19
19
|
|
20
20
|
##
|
21
21
|
# :attr: source
|
22
|
-
# The alternative method to read a property value when serializing
|
23
|
-
# an object.
|
22
|
+
# The alternative method to read a property value when serializing an object.
|
24
23
|
attribute :source, Symbol
|
25
24
|
|
26
25
|
##
|
@@ -42,8 +41,8 @@ module Jsapi
|
|
42
41
|
@schema = Schema.new(keywords)
|
43
42
|
end
|
44
43
|
|
45
|
-
# Returns true if the level of existence is greater than or equal to
|
46
|
-
#
|
44
|
+
# Returns true if the level of existence is greater than or equal to +ALLOW_NIL+,
|
45
|
+
# false otherwise.
|
47
46
|
def required?
|
48
47
|
schema.existence >= Existence::ALLOW_NIL
|
49
48
|
end
|
@@ -2,9 +2,15 @@
|
|
2
2
|
|
3
3
|
module Jsapi
|
4
4
|
module Meta
|
5
|
+
# Maps a +StandardError+ class to a response status.
|
5
6
|
class RescueHandler
|
7
|
+
# The response status.
|
6
8
|
attr_reader :status
|
7
9
|
|
10
|
+
# Creates a new rescue handler to map +klass+ to +status+. The default response status
|
11
|
+
# is <code>"default"</code>.
|
12
|
+
#
|
13
|
+
# Raises an +ArgumentError+ if +klass+ isn't a +StandardError+ class.
|
8
14
|
def initialize(klass, status: nil)
|
9
15
|
unless klass.is_a?(Class) && klass.ancestors.include?(StandardError)
|
10
16
|
raise ArgumentError, "#{klass.inspect} must be a standard error class"
|
@@ -18,6 +24,7 @@ module Jsapi
|
|
18
24
|
"#<#{self.class.name} class: #{@klass}, status: #{@status.inspect}>"
|
19
25
|
end
|
20
26
|
|
27
|
+
# Returns true if +exception+ is an instance of the class to be mapped, false otherwise.
|
21
28
|
def match?(exception)
|
22
29
|
exception.is_a?(@klass)
|
23
30
|
end
|
@@ -12,7 +12,7 @@ module Jsapi
|
|
12
12
|
|
13
13
|
##
|
14
14
|
# :attr: default
|
15
|
-
# The
|
15
|
+
# The default value.
|
16
16
|
attribute :default
|
17
17
|
|
18
18
|
##
|
@@ -22,7 +22,7 @@ module Jsapi
|
|
22
22
|
|
23
23
|
##
|
24
24
|
# :attr: description
|
25
|
-
# The
|
25
|
+
# The description of the schema.
|
26
26
|
attribute :description, ::String
|
27
27
|
|
28
28
|
##
|
@@ -32,23 +32,22 @@ module Jsapi
|
|
32
32
|
|
33
33
|
##
|
34
34
|
# :attr: examples
|
35
|
-
# The
|
35
|
+
# The samples matching the schema.
|
36
36
|
attribute :examples, [::Object]
|
37
37
|
|
38
38
|
##
|
39
39
|
# :attr: external_docs
|
40
|
-
# The
|
40
|
+
# The OpenAPI::ExternalDocumentation object.
|
41
41
|
attribute :external_docs, OpenAPI::ExternalDocumentation
|
42
42
|
|
43
43
|
##
|
44
44
|
# :attr: existence
|
45
|
-
# The level of Existence. The default level of existence
|
46
|
-
# is +ALLOW_OMITTED+.
|
45
|
+
# The level of Existence. The default level of existence is +ALLOW_OMITTED+.
|
47
46
|
attribute :existence, Existence, default: Existence::ALLOW_OMITTED
|
48
47
|
|
49
48
|
##
|
50
49
|
# :attr: title
|
51
|
-
# The
|
50
|
+
# The title of the schema.
|
52
51
|
attribute :title, String
|
53
52
|
|
54
53
|
##
|
@@ -73,8 +72,7 @@ module Jsapi
|
|
73
72
|
@enum = value
|
74
73
|
end
|
75
74
|
|
76
|
-
# Returns true if and only if values can be +null+ as specified
|
77
|
-
# by \JSON \Schema.
|
75
|
+
# Returns true if and only if values can be +null+ as specified by \JSON \Schema.
|
78
76
|
def nullable?
|
79
77
|
existence <= Existence::ALLOW_NIL
|
80
78
|
end
|
@@ -9,8 +9,7 @@ module Jsapi
|
|
9
9
|
|
10
10
|
##
|
11
11
|
# :attr: existence
|
12
|
-
# The level of Existence. The default level of existence
|
13
|
-
# is +ALLOW_OMITTED+.
|
12
|
+
# The level of Existence. The default level of existence is +ALLOW_OMITTED+.
|
14
13
|
attribute :existence, Existence, default: Existence::ALLOW_OMITTED
|
15
14
|
|
16
15
|
def resolve(definitions) # :nodoc:
|