jsapi 2.1.2 → 3.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/client/base.rb +182 -0
- data/lib/jsapi/client/exceptions.rb +45 -0
- data/lib/jsapi/client/request.rb +204 -0
- data/lib/jsapi/client/response.rb +120 -0
- data/lib/jsapi/client/session/base.rb +61 -0
- data/lib/jsapi/client/session/logger.rb +52 -0
- data/lib/jsapi/client/session/single_request.rb +16 -0
- data/lib/jsapi/client/session/test/class_methods.rb +49 -0
- data/lib/jsapi/client/session/test/response.rb +56 -0
- data/lib/jsapi/client/session/test/spy.rb +43 -0
- data/lib/jsapi/client/session/test.rb +17 -0
- data/lib/jsapi/client/session.rb +6 -0
- data/lib/jsapi/client.rb +7 -0
- data/lib/jsapi/configuration.rb +2 -2
- data/lib/jsapi/controller/authentication/credentials/http/bearer.rb +5 -12
- data/lib/jsapi/controller/authentication/credentials.rb +4 -4
- data/lib/jsapi/controller/authentication.rb +3 -3
- data/lib/jsapi/controller/methods.rb +43 -77
- data/lib/jsapi/controller/parameters.rb +6 -6
- data/lib/jsapi/controller/response.rb +7 -7
- data/lib/jsapi/{meta/definitions.rb → definition/api.rb} +62 -40
- data/lib/jsapi/{meta → definition}/callable/symbol_evaluator.rb +1 -1
- data/lib/jsapi/{meta → definition}/callable/symbol_sequence_evaluator.rb +1 -1
- data/lib/jsapi/{meta → definition}/callable.rb +1 -1
- data/lib/jsapi/{meta → definition}/callback/base.rb +5 -5
- data/lib/jsapi/{meta → definition}/callback/reference.rb +1 -1
- data/lib/jsapi/{meta → definition}/callback.rb +1 -1
- data/lib/jsapi/{meta → definition}/contact.rb +1 -1
- data/lib/jsapi/{meta → definition}/content.rb +11 -11
- data/lib/jsapi/{meta → definition}/defaults.rb +1 -1
- data/lib/jsapi/{meta → definition}/example/base.rb +1 -1
- data/lib/jsapi/{meta → definition}/example/builder.rb +4 -4
- data/lib/jsapi/{meta → definition}/example/reference.rb +1 -1
- data/lib/jsapi/{meta → definition}/example.rb +1 -1
- data/lib/jsapi/{meta → definition}/existence.rb +1 -1
- data/lib/jsapi/{meta → definition}/external_documentation.rb +1 -1
- data/lib/jsapi/{meta → definition}/header/base.rb +1 -1
- data/lib/jsapi/{meta → definition}/header/reference.rb +1 -1
- data/lib/jsapi/{meta → definition}/header.rb +1 -1
- data/lib/jsapi/{meta → definition}/info.rb +1 -1
- data/lib/jsapi/{meta → definition}/license.rb +1 -1
- data/lib/jsapi/{meta → definition}/link/base.rb +1 -1
- data/lib/jsapi/{meta → definition}/link/reference.rb +1 -1
- data/lib/jsapi/{meta → definition}/link.rb +1 -1
- data/lib/jsapi/{meta → definition}/model/attributes/class_methods.rb +1 -1
- data/lib/jsapi/{meta → definition}/model/attributes/frozen_error.rb +1 -1
- data/lib/jsapi/{meta → definition}/model/attributes/type_caster.rb +2 -2
- data/lib/jsapi/{meta → definition}/model/attributes.rb +1 -1
- data/lib/jsapi/{meta → definition}/model/base.rb +1 -1
- data/lib/jsapi/{meta → definition}/model/reference.rb +11 -11
- data/lib/jsapi/{meta → definition}/model/wrappable.rb +3 -3
- data/lib/jsapi/{meta → definition}/model/wrapper.rb +5 -5
- data/lib/jsapi/{meta → definition}/oauth_flow.rb +1 -1
- data/lib/jsapi/{meta → definition}/openapi/extensions.rb +1 -1
- data/lib/jsapi/{meta → definition}/openapi/path_item.rb +5 -5
- data/lib/jsapi/{meta → definition}/openapi/version.rb +2 -2
- data/lib/jsapi/{meta → definition}/openapi.rb +1 -1
- data/lib/jsapi/{meta → definition}/operation.rb +108 -62
- data/lib/jsapi/{meta → definition}/parameter/base.rb +11 -11
- data/lib/jsapi/{meta → definition}/parameter/reference.rb +5 -5
- data/lib/jsapi/{meta → definition}/parameter/wrapper.rb +2 -2
- data/lib/jsapi/{meta → definition}/parameter.rb +1 -1
- data/lib/jsapi/{meta → definition}/path.rb +1 -1
- data/lib/jsapi/{meta → definition}/pathname.rb +1 -1
- data/lib/jsapi/{meta → definition}/property.rb +2 -2
- data/lib/jsapi/{meta → definition}/reference_error.rb +1 -1
- data/lib/jsapi/{meta → definition}/request_body/base.rb +1 -1
- data/lib/jsapi/{meta → definition}/request_body/reference.rb +1 -1
- data/lib/jsapi/{meta → definition}/request_body/wrapper.rb +2 -2
- data/lib/jsapi/{meta → definition}/request_body.rb +1 -1
- data/lib/jsapi/{meta → definition}/rescue_handler.rb +1 -1
- data/lib/jsapi/{meta → definition}/response/base.rb +4 -4
- data/lib/jsapi/{meta → definition}/response/reference.rb +1 -1
- data/lib/jsapi/{meta → definition}/response/wrapper.rb +17 -5
- data/lib/jsapi/{meta → definition}/response.rb +1 -1
- data/lib/jsapi/{meta → definition}/schema/additional_properties.rb +2 -2
- data/lib/jsapi/{meta → definition}/schema/array.rb +2 -2
- data/lib/jsapi/{meta → definition}/schema/base.rb +1 -1
- data/lib/jsapi/{meta → definition}/schema/boolean.rb +1 -1
- data/lib/jsapi/{meta → definition}/schema/boundary.rb +1 -1
- data/lib/jsapi/{meta → definition}/schema/conversion.rb +1 -1
- data/lib/jsapi/{meta → definition}/schema/discriminator.rb +1 -1
- data/lib/jsapi/{meta → definition}/schema/integer.rb +1 -1
- data/lib/jsapi/{meta → definition}/schema/number.rb +1 -1
- data/lib/jsapi/{meta → definition}/schema/numeric.rb +1 -1
- data/lib/jsapi/{meta → definition}/schema/object.rb +13 -13
- data/lib/jsapi/{meta → definition}/schema/reference.rb +1 -1
- data/lib/jsapi/{meta → definition}/schema/string.rb +1 -1
- data/lib/jsapi/{meta → definition}/schema/validation/base.rb +1 -1
- data/lib/jsapi/{meta → definition}/schema/validation/enum.rb +1 -1
- data/lib/jsapi/{meta → definition}/schema/validation/max_items.rb +1 -1
- data/lib/jsapi/{meta → definition}/schema/validation/max_length.rb +1 -1
- data/lib/jsapi/{meta → definition}/schema/validation/maximum.rb +1 -1
- data/lib/jsapi/{meta → definition}/schema/validation/min_items.rb +1 -1
- data/lib/jsapi/{meta → definition}/schema/validation/min_length.rb +1 -1
- data/lib/jsapi/{meta → definition}/schema/validation/minimum.rb +1 -1
- data/lib/jsapi/{meta → definition}/schema/validation/multiple_of.rb +1 -1
- data/lib/jsapi/{meta → definition}/schema/validation/pattern.rb +1 -1
- data/lib/jsapi/{meta → definition}/schema/wrapper.rb +18 -4
- data/lib/jsapi/{meta → definition}/schema.rb +5 -5
- data/lib/jsapi/{meta → definition}/security_requirement.rb +1 -1
- data/lib/jsapi/{meta → definition}/security_scheme/api_key.rb +1 -1
- data/lib/jsapi/{meta → definition}/security_scheme/base.rb +1 -1
- data/lib/jsapi/{meta → definition}/security_scheme/http/basic.rb +1 -1
- data/lib/jsapi/{meta → definition}/security_scheme/http/bearer.rb +1 -1
- data/lib/jsapi/{meta → definition}/security_scheme/http/other.rb +1 -1
- data/lib/jsapi/{meta → definition}/security_scheme/http.rb +1 -1
- data/lib/jsapi/{meta → definition}/security_scheme/mutual_tls.rb +1 -1
- data/lib/jsapi/{meta → definition}/security_scheme/oauth2.rb +1 -1
- data/lib/jsapi/{meta → definition}/security_scheme/open_id_connect.rb +1 -1
- data/lib/jsapi/{meta → definition}/security_scheme.rb +1 -1
- data/lib/jsapi/{meta → definition}/server.rb +24 -1
- data/lib/jsapi/{meta → definition}/server_variable.rb +1 -1
- data/lib/jsapi/{meta → definition}/tag.rb +1 -1
- data/lib/jsapi/definition.rb +33 -0
- data/lib/jsapi/dsl/{definitions.rb → api.rb} +48 -48
- data/lib/jsapi/dsl/base.rb +7 -7
- data/lib/jsapi/dsl/class_methods.rb +34 -32
- data/lib/jsapi/dsl/examples.rb +1 -1
- data/lib/jsapi/dsl/operation.rb +9 -7
- data/lib/jsapi/dsl/parameter.rb +1 -1
- data/lib/jsapi/dsl/path.rb +8 -6
- data/lib/jsapi/dsl/response.rb +5 -5
- data/lib/jsapi/dsl/schema.rb +17 -17
- data/lib/jsapi/dsl/shared_operation_methods.rb +11 -26
- data/lib/jsapi/dsl.rb +2 -2
- data/lib/jsapi/model/errors.rb +3 -3
- data/lib/jsapi/status/code.rb +20 -0
- data/lib/jsapi/support/messages.rb +27 -0
- data/lib/jsapi/support.rb +3 -0
- data/lib/jsapi/version.rb +1 -1
- data/lib/jsapi.rb +3 -3
- metadata +115 -102
- data/lib/jsapi/jsonify_error.rb +0 -17
- data/lib/jsapi/messages.rb +0 -19
- data/lib/jsapi/meta.rb +0 -38
- /data/lib/jsapi/{meta → definition}/model.rb +0 -0
- /data/lib/jsapi/{meta → definition}/schema/validation.rb +0 -0
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Jsapi
|
|
4
|
-
module
|
|
5
|
-
|
|
4
|
+
module Definition
|
|
5
|
+
# Raised when no operation with the specified name is found.
|
|
6
|
+
class OperationNotFound < StandardError
|
|
7
|
+
def initialize(operation_name)
|
|
8
|
+
super("operation not found: #{operation_name}")
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
class API < Model::Base
|
|
6
13
|
include OpenAPI::Extensions
|
|
7
14
|
|
|
8
15
|
##
|
|
9
16
|
# :attr: base_path
|
|
10
|
-
# The base path of the API.
|
|
17
|
+
# The base path of the \API.
|
|
11
18
|
#
|
|
12
19
|
# Applies to \OpenAPI 2.0.
|
|
13
20
|
attribute :base_path, Pathname
|
|
@@ -46,7 +53,7 @@ module Jsapi
|
|
|
46
53
|
|
|
47
54
|
##
|
|
48
55
|
# :attr: host
|
|
49
|
-
# The host serving the API.
|
|
56
|
+
# The host serving the \API.
|
|
50
57
|
#
|
|
51
58
|
# Applies to \OpenAPI 2.0.
|
|
52
59
|
attribute :host, String
|
|
@@ -108,7 +115,7 @@ module Jsapi
|
|
|
108
115
|
|
|
109
116
|
##
|
|
110
117
|
# :attr: schemes
|
|
111
|
-
# The transfer protocols supported by the API. Can contain one or more of:
|
|
118
|
+
# The transfer protocols supported by the \API. Can contain one or more of:
|
|
112
119
|
#
|
|
113
120
|
# - <code>"http"</code>
|
|
114
121
|
# - <code>"https"</code>
|
|
@@ -132,7 +139,7 @@ module Jsapi
|
|
|
132
139
|
|
|
133
140
|
##
|
|
134
141
|
# :attr: servers
|
|
135
|
-
# The servers providing the API.
|
|
142
|
+
# The servers providing the \API.
|
|
136
143
|
#
|
|
137
144
|
# Applies to \OpenAPI 3.0 and higher.
|
|
138
145
|
attribute :servers, [Server]
|
|
@@ -145,7 +152,7 @@ module Jsapi
|
|
|
145
152
|
# The class to which this instance is assigned.
|
|
146
153
|
attr_reader :owner
|
|
147
154
|
|
|
148
|
-
# The +
|
|
155
|
+
# The +API+ instance from which this instance inherits.
|
|
149
156
|
attr_reader :parent
|
|
150
157
|
|
|
151
158
|
def initialize(keywords = {})
|
|
@@ -155,8 +162,8 @@ module Jsapi
|
|
|
155
162
|
included = keywords.delete(:include)
|
|
156
163
|
super(keywords)
|
|
157
164
|
|
|
158
|
-
Array(included).each do |
|
|
159
|
-
include(
|
|
165
|
+
Array(included).each do |api|
|
|
166
|
+
include(api)
|
|
160
167
|
end
|
|
161
168
|
@parent&.inherited(self)
|
|
162
169
|
end
|
|
@@ -188,12 +195,12 @@ module Jsapi
|
|
|
188
195
|
end
|
|
189
196
|
end
|
|
190
197
|
|
|
191
|
-
# Returns an array containing itself and all of the +
|
|
198
|
+
# Returns an array containing itself and all of the +API+ instances
|
|
192
199
|
# inherited or included.
|
|
193
200
|
def ancestors
|
|
194
201
|
@ancestors ||= [self].tap do |ancestors|
|
|
195
|
-
[@
|
|
196
|
-
ancestors.push(*
|
|
202
|
+
[@included_apis, @parent].flatten.each do |api|
|
|
203
|
+
ancestors.push(*api.ancestors) if api
|
|
197
204
|
end
|
|
198
205
|
end.uniq
|
|
199
206
|
end
|
|
@@ -229,8 +236,8 @@ module Jsapi
|
|
|
229
236
|
|
|
230
237
|
cache_path_attribute(arg, name) do
|
|
231
238
|
arg.ancestors.lazy.filter_map do |pathname|
|
|
232
|
-
ancestors.lazy.filter_map do |
|
|
233
|
-
|
|
239
|
+
ancestors.lazy.filter_map do |api|
|
|
240
|
+
api.path(pathname)&.public_send(name).presence
|
|
234
241
|
end.first
|
|
235
242
|
end.first
|
|
236
243
|
end
|
|
@@ -255,8 +262,8 @@ module Jsapi
|
|
|
255
262
|
|
|
256
263
|
cache_path_attribute(arg, name) do
|
|
257
264
|
arg.ancestors.flat_map do |pathname|
|
|
258
|
-
ancestors.filter_map do |
|
|
259
|
-
|
|
265
|
+
ancestors.filter_map do |api|
|
|
266
|
+
api.path(pathname)&.send(name)
|
|
260
267
|
end
|
|
261
268
|
end.reduce({}, &:reverse_merge).presence
|
|
262
269
|
end
|
|
@@ -280,8 +287,8 @@ module Jsapi
|
|
|
280
287
|
|
|
281
288
|
cache_path_attribute(arg, name) do
|
|
282
289
|
arg.ancestors.filter_map do |pathname|
|
|
283
|
-
ancestors.filter_map do |
|
|
284
|
-
|
|
290
|
+
ancestors.filter_map do |api|
|
|
291
|
+
api.path(pathname)&.send(name)
|
|
285
292
|
end
|
|
286
293
|
end.flatten.uniq.presence
|
|
287
294
|
end
|
|
@@ -298,7 +305,8 @@ module Jsapi
|
|
|
298
305
|
cached_attributes[:security_requirements]
|
|
299
306
|
end
|
|
300
307
|
|
|
301
|
-
# Returns the operation with the specified name
|
|
308
|
+
# Returns the operation with the specified name or +nil+ if no such
|
|
309
|
+
# operation is found.
|
|
302
310
|
def find_operation(name = nil)
|
|
303
311
|
name = name&.to_s
|
|
304
312
|
|
|
@@ -313,6 +321,15 @@ module Jsapi
|
|
|
313
321
|
end
|
|
314
322
|
end
|
|
315
323
|
|
|
324
|
+
# Like +find_operation+, except that it raises an OperationNotFound error
|
|
325
|
+
# when no such operation is found.
|
|
326
|
+
def find_operation!(name = nil)
|
|
327
|
+
operation = find_operation(name)
|
|
328
|
+
return operation if operation
|
|
329
|
+
|
|
330
|
+
raise OperationNotFound.new(name)
|
|
331
|
+
end
|
|
332
|
+
|
|
316
333
|
##
|
|
317
334
|
# :method: find_example
|
|
318
335
|
# Returns the reusable example with the specified name.
|
|
@@ -344,17 +361,17 @@ module Jsapi
|
|
|
344
361
|
end
|
|
345
362
|
end
|
|
346
363
|
|
|
347
|
-
# Includes +
|
|
348
|
-
def include(
|
|
349
|
-
if circular_dependency?(
|
|
364
|
+
# Includes +api+.
|
|
365
|
+
def include(api)
|
|
366
|
+
if circular_dependency?(api)
|
|
350
367
|
raise ArgumentError,
|
|
351
368
|
'detected circular dependency between ' \
|
|
352
369
|
"#{owner.inspect} and " \
|
|
353
|
-
"#{
|
|
370
|
+
"#{api.owner.inspect}"
|
|
354
371
|
end
|
|
355
372
|
|
|
356
|
-
(@
|
|
357
|
-
|
|
373
|
+
(@included_apis ||= []) << api
|
|
374
|
+
api.included(self)
|
|
358
375
|
invalidate_ancestors
|
|
359
376
|
self
|
|
360
377
|
end
|
|
@@ -497,37 +514,42 @@ module Jsapi
|
|
|
497
514
|
end
|
|
498
515
|
|
|
499
516
|
# Returns the first RescueHandler capable to handle +exception+, or nil
|
|
500
|
-
# if no one
|
|
517
|
+
# if no one is found.
|
|
501
518
|
def rescue_handler_for(exception)
|
|
502
519
|
cached_attributes[:rescue_handlers].find { |r| r.match?(exception) }
|
|
503
520
|
end
|
|
504
521
|
|
|
522
|
+
# Returns the server with the specified name or +nil+ if no such server is present.
|
|
523
|
+
def server(name)
|
|
524
|
+
cached_attributes[:servers].find { |server| server.name == name } unless name.nil?
|
|
525
|
+
end
|
|
526
|
+
|
|
505
527
|
protected
|
|
506
528
|
|
|
507
|
-
# The +
|
|
529
|
+
# The +API+ instances that directly inherit from this instance.
|
|
508
530
|
attr_reader :children
|
|
509
531
|
|
|
510
|
-
# The +
|
|
511
|
-
attr_reader :
|
|
532
|
+
# The +API+ instances that directly include this instance.
|
|
533
|
+
attr_reader :dependent_apis
|
|
512
534
|
|
|
513
|
-
# The +
|
|
514
|
-
attr_reader :
|
|
535
|
+
# The +API+ instances included.
|
|
536
|
+
attr_reader :included_apis
|
|
515
537
|
|
|
516
538
|
def attribute_changed(*) # :nodoc:
|
|
517
539
|
invalidate_attributes
|
|
518
540
|
super
|
|
519
541
|
end
|
|
520
542
|
|
|
521
|
-
# Invoked whenever it is included in another +
|
|
522
|
-
def included(
|
|
523
|
-
(@
|
|
543
|
+
# Invoked whenever it is included in another +API+ instance.
|
|
544
|
+
def included(api)
|
|
545
|
+
(@dependent_apis ||= []) << api
|
|
524
546
|
end
|
|
525
547
|
|
|
526
548
|
# rubocop:disable Lint/MissingSuper
|
|
527
549
|
|
|
528
|
-
# Invoked whenever it is inherited by another +
|
|
529
|
-
def inherited(
|
|
530
|
-
(@children ||= []) <<
|
|
550
|
+
# Invoked whenever it is inherited by another +API+ instance.
|
|
551
|
+
def inherited(api)
|
|
552
|
+
(@children ||= []) << api
|
|
531
553
|
end
|
|
532
554
|
|
|
533
555
|
# rubocop:enable Lint/MissingSuper
|
|
@@ -592,9 +614,9 @@ module Jsapi
|
|
|
592
614
|
|
|
593
615
|
def circular_dependency?(other)
|
|
594
616
|
return true if other == self
|
|
595
|
-
return false unless other.
|
|
617
|
+
return false unless other.included_apis&.any?
|
|
596
618
|
|
|
597
|
-
other.
|
|
619
|
+
other.included_apis.any? { |included| circular_dependency?(included) }
|
|
598
620
|
end
|
|
599
621
|
|
|
600
622
|
def default_operation_name
|
|
@@ -616,7 +638,7 @@ module Jsapi
|
|
|
616
638
|
end
|
|
617
639
|
|
|
618
640
|
def each_descendant(&block)
|
|
619
|
-
[*@children, *
|
|
641
|
+
[*@children, *dependent_apis].each(&block)
|
|
620
642
|
nil
|
|
621
643
|
end
|
|
622
644
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Jsapi
|
|
4
|
-
module
|
|
4
|
+
module Definition
|
|
5
5
|
module Parameter; end
|
|
6
6
|
class Operation < Model::Base; end
|
|
7
7
|
|
|
@@ -50,13 +50,13 @@ module Jsapi
|
|
|
50
50
|
|
|
51
51
|
# Returns a hash representing the \OpenAPI path item object that describes
|
|
52
52
|
# the operations.
|
|
53
|
-
def to_openapi(version,
|
|
53
|
+
def to_openapi(version, api)
|
|
54
54
|
OpenAPI::PathItem.new(
|
|
55
55
|
operations.values,
|
|
56
56
|
description: description,
|
|
57
57
|
summary: summary,
|
|
58
58
|
parameters: parameters
|
|
59
|
-
).to_openapi(version,
|
|
59
|
+
).to_openapi(version, api)
|
|
60
60
|
end
|
|
61
61
|
end
|
|
62
62
|
|
|
@@ -76,9 +76,9 @@ module Jsapi
|
|
|
76
76
|
end
|
|
77
77
|
|
|
78
78
|
# Returns a hash representing the \OpenAPI callback object.
|
|
79
|
-
def to_openapi(version,
|
|
79
|
+
def to_openapi(version, api)
|
|
80
80
|
expressions.transform_values do |operations|
|
|
81
|
-
operations.to_openapi(version,
|
|
81
|
+
operations.to_openapi(version, api)
|
|
82
82
|
end
|
|
83
83
|
end
|
|
84
84
|
end
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Jsapi
|
|
4
|
-
module
|
|
4
|
+
module Definition
|
|
5
5
|
# Specifies the content of a request body or response.
|
|
6
6
|
class Content < Model::Base
|
|
7
7
|
include OpenAPI::Extensions
|
|
8
8
|
|
|
9
9
|
class Wrapper < Model::Wrapper
|
|
10
10
|
def schema
|
|
11
|
-
@schema ||= Schema.wrap(super,
|
|
11
|
+
@schema ||= Schema.wrap(super, api)
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
include Model::Wrappable
|
|
16
16
|
|
|
17
|
-
delegate_missing_to :schema
|
|
17
|
+
delegate_missing_to :schema, allow_nil: true
|
|
18
18
|
|
|
19
19
|
##
|
|
20
20
|
# :attr: examples
|
|
@@ -33,20 +33,20 @@ module Jsapi
|
|
|
33
33
|
add_example(value: keywords.delete(:example)) if keywords.key?(:example)
|
|
34
34
|
keywords[:ref] = keywords.delete(:schema) if keywords.key?(:schema)
|
|
35
35
|
|
|
36
|
-
@schema = Schema.new(keywords)
|
|
36
|
+
@schema = Schema.new(keywords) if keywords[:type] || keywords[:ref]
|
|
37
37
|
end
|
|
38
38
|
|
|
39
39
|
# Returns the data value of the first example.
|
|
40
|
-
def example_data_value(
|
|
40
|
+
def example_data_value(api, locale: nil)
|
|
41
41
|
examples
|
|
42
42
|
.values.first
|
|
43
|
-
&.resolve(
|
|
44
|
-
&.data_value(builder: example_builder(
|
|
43
|
+
&.resolve(api)
|
|
44
|
+
&.data_value(builder: example_builder(api, locale))
|
|
45
45
|
end
|
|
46
46
|
|
|
47
47
|
# Returns a hash representing the \OpenAPI media type object describing
|
|
48
48
|
# the content. Applies to \OpenAPI 3.0 and higher.
|
|
49
|
-
def to_openapi(version,
|
|
49
|
+
def to_openapi(version, api = nil, locale: nil, media_type: nil)
|
|
50
50
|
version = OpenAPI::Version.from(version)
|
|
51
51
|
example_builder = nil
|
|
52
52
|
|
|
@@ -59,7 +59,7 @@ module Jsapi
|
|
|
59
59
|
end,
|
|
60
60
|
examples:
|
|
61
61
|
examples.transform_values do |example|
|
|
62
|
-
example_builder ||= example_builder(
|
|
62
|
+
example_builder ||= example_builder(api, locale)
|
|
63
63
|
example.to_openapi(version, builder: example_builder)
|
|
64
64
|
end.presence
|
|
65
65
|
)
|
|
@@ -67,8 +67,8 @@ module Jsapi
|
|
|
67
67
|
|
|
68
68
|
private
|
|
69
69
|
|
|
70
|
-
def example_builder(
|
|
71
|
-
Example::Builder.new(schema,
|
|
70
|
+
def example_builder(api, locale)
|
|
71
|
+
Example::Builder.new(schema, api, locale: locale) if api.present?
|
|
72
72
|
end
|
|
73
73
|
end
|
|
74
74
|
end
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Jsapi
|
|
4
|
-
module
|
|
4
|
+
module Definition
|
|
5
5
|
module Example
|
|
6
6
|
class Builder # :nodoc:
|
|
7
|
-
def initialize(schema,
|
|
8
|
-
@schema = Schema.wrap(schema,
|
|
7
|
+
def initialize(schema, api, locale: nil)
|
|
8
|
+
@schema = Schema.wrap(schema, api)
|
|
9
9
|
@locale = locale
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def generate_json(object, omit: nil)
|
|
13
|
-
raise ArgumentError, Messages.invalid_value(
|
|
13
|
+
raise ArgumentError, Support::Messages.invalid_value(
|
|
14
14
|
name: 'omit',
|
|
15
15
|
value: omit,
|
|
16
16
|
valid_values: %i[empty nil]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Jsapi
|
|
4
|
-
module
|
|
4
|
+
module Definition
|
|
5
5
|
module Model
|
|
6
6
|
module Attributes
|
|
7
7
|
class TypeCaster
|
|
@@ -43,7 +43,7 @@ module Jsapi
|
|
|
43
43
|
casted_value = @caster.call(value)
|
|
44
44
|
return casted_value unless @values&.exclude?(casted_value)
|
|
45
45
|
|
|
46
|
-
raise ArgumentError, Messages.invalid_value(
|
|
46
|
+
raise ArgumentError, Support::Messages.invalid_value(
|
|
47
47
|
name: @name,
|
|
48
48
|
value: casted_value,
|
|
49
49
|
valid_values: @values
|