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,14 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Jsapi
|
|
4
|
-
module
|
|
4
|
+
module Definition
|
|
5
5
|
module Model
|
|
6
6
|
# The base reference class.
|
|
7
7
|
class Reference < Base
|
|
8
8
|
class Resolver # :nodoc:
|
|
9
|
-
def initialize(reference,
|
|
9
|
+
def initialize(reference, api)
|
|
10
10
|
@reference = reference
|
|
11
|
-
@
|
|
11
|
+
@api = api
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
protected
|
|
@@ -24,8 +24,8 @@ module Jsapi
|
|
|
24
24
|
return result unless result.nil?
|
|
25
25
|
|
|
26
26
|
@reference
|
|
27
|
-
.resolve(@
|
|
28
|
-
.resolve_lazily(@
|
|
27
|
+
.resolve(@api, deep: false)
|
|
28
|
+
.resolve_lazily(@api)
|
|
29
29
|
.send(name, ...)
|
|
30
30
|
end
|
|
31
31
|
end
|
|
@@ -66,21 +66,21 @@ module Jsapi
|
|
|
66
66
|
true
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
# Resolves the reference by looking up the referred object in +
|
|
69
|
+
# Resolves the reference by looking up the referred object in +api+.
|
|
70
70
|
#
|
|
71
71
|
# Raises a ReferenceError if the reference could not be resolved.
|
|
72
|
-
def resolve(
|
|
73
|
-
object =
|
|
72
|
+
def resolve(api, deep: true)
|
|
73
|
+
object = api.send("find_#{self.class.component_type}", ref)
|
|
74
74
|
raise ReferenceError, ref if object.nil?
|
|
75
75
|
|
|
76
|
-
deep ? object.resolve(
|
|
76
|
+
deep ? object.resolve(api, deep: true) : object
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
# Lazily resolves the reference.
|
|
80
80
|
#
|
|
81
81
|
# Raises a ReferenceError if the reference could not be resolved.
|
|
82
|
-
def resolve_lazily(
|
|
83
|
-
Resolver.new(self,
|
|
82
|
+
def resolve_lazily(api)
|
|
83
|
+
Resolver.new(self, api)
|
|
84
84
|
end
|
|
85
85
|
|
|
86
86
|
# Returns a hash representing the \OpenAPI reference object.
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Jsapi
|
|
4
|
-
module
|
|
4
|
+
module Definition
|
|
5
5
|
module Model
|
|
6
6
|
# Defines a +wrap+ class method to wrap an instance of the given class.
|
|
7
7
|
module Wrappable
|
|
8
8
|
def self.included(base) # :nodoc:
|
|
9
9
|
class << base
|
|
10
|
-
define_method(:wrap) do |model,
|
|
10
|
+
define_method(:wrap) do |model, api|
|
|
11
11
|
return if model.nil?
|
|
12
12
|
|
|
13
13
|
wrapper_class = "#{name}::Wrapper".constantize
|
|
14
14
|
return model if model.is_a?(wrapper_class)
|
|
15
15
|
|
|
16
|
-
wrapper_class.new(model,
|
|
16
|
+
wrapper_class.new(model, api)
|
|
17
17
|
end
|
|
18
18
|
end
|
|
19
19
|
end
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Jsapi
|
|
4
|
-
module
|
|
4
|
+
module Definition
|
|
5
5
|
module Model
|
|
6
6
|
# Wraps a meta model
|
|
7
7
|
class Wrapper < SimpleDelegator
|
|
8
|
-
attr_reader :
|
|
8
|
+
attr_reader :api
|
|
9
9
|
|
|
10
|
-
def initialize(model,
|
|
11
|
-
super(model.resolve(
|
|
12
|
-
@
|
|
10
|
+
def initialize(model, api)
|
|
11
|
+
super(model.resolve(api))
|
|
12
|
+
@api = api
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
def ==(other) # :nodoc:
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Jsapi
|
|
4
|
-
module
|
|
4
|
+
module Definition
|
|
5
5
|
module OpenAPI
|
|
6
6
|
class PathItem # :nodoc:
|
|
7
7
|
def initialize(operations, keywords = {})
|
|
@@ -12,7 +12,7 @@ module Jsapi
|
|
|
12
12
|
@parameters = keywords[:parameters]
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
def to_openapi(version,
|
|
15
|
+
def to_openapi(version, api)
|
|
16
16
|
version = OpenAPI::Version.from(version)
|
|
17
17
|
|
|
18
18
|
{}.tap do |fields|
|
|
@@ -27,10 +27,10 @@ module Jsapi
|
|
|
27
27
|
standardized_method = method.downcase
|
|
28
28
|
|
|
29
29
|
if standard_method?(standardized_method, version)
|
|
30
|
-
fields[standardized_method] = operation.to_openapi(version,
|
|
30
|
+
fields[standardized_method] = operation.to_openapi(version, api)
|
|
31
31
|
elsif version >= OpenAPI::V3_2
|
|
32
32
|
additional_operations = fields[:additionalOperations] ||= {}
|
|
33
|
-
additional_operations[method] = operation.to_openapi(version,
|
|
33
|
+
additional_operations[method] = operation.to_openapi(version, api)
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
|
|
@@ -42,7 +42,7 @@ module Jsapi
|
|
|
42
42
|
# Parameters
|
|
43
43
|
if @parameters.present?
|
|
44
44
|
fields[:parameters] = @parameters.values.map do |parameter|
|
|
45
|
-
parameter.to_openapi(version,
|
|
45
|
+
parameter.to_openapi(version, api)
|
|
46
46
|
end
|
|
47
47
|
end
|
|
48
48
|
end
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Jsapi
|
|
4
|
-
module
|
|
4
|
+
module Definition
|
|
5
5
|
module OpenAPI
|
|
6
6
|
class Version
|
|
7
7
|
include Comparable
|
|
@@ -60,7 +60,7 @@ module Jsapi
|
|
|
60
60
|
when [3, 1]
|
|
61
61
|
'3.1.2'
|
|
62
62
|
when [3, 2]
|
|
63
|
-
'3.2.
|
|
63
|
+
'3.2.1'
|
|
64
64
|
else
|
|
65
65
|
"#{major}.#{minor}"
|
|
66
66
|
end
|
|
@@ -1,14 +1,54 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Jsapi
|
|
4
|
-
module
|
|
4
|
+
module Definition
|
|
5
|
+
# Raised when no response matches +status+.
|
|
6
|
+
class ResponseNotFound < StandardError
|
|
7
|
+
def initialize(operation, status)
|
|
8
|
+
super(
|
|
9
|
+
if operation.responses.none?
|
|
10
|
+
"#{operation.name.inspect} has no responses"
|
|
11
|
+
else
|
|
12
|
+
"#{operation.name.inspect} has no response for status #{status}"
|
|
13
|
+
end
|
|
14
|
+
)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
5
18
|
# Specifies an API operation.
|
|
6
19
|
class Operation < Model::Base
|
|
7
20
|
include OpenAPI::Extensions
|
|
8
21
|
|
|
9
22
|
class Wrapper < Model::Wrapper
|
|
10
|
-
|
|
11
|
-
|
|
23
|
+
##
|
|
24
|
+
# :attr_reader: model
|
|
25
|
+
# The model class of the wrapped operation or the default model class
|
|
26
|
+
# for the path.
|
|
27
|
+
|
|
28
|
+
##
|
|
29
|
+
# :attr_reader: parameters
|
|
30
|
+
# The parameters of the wrapped operation in combination with the
|
|
31
|
+
# parameters applying to all operations in the path.
|
|
32
|
+
|
|
33
|
+
##
|
|
34
|
+
# :attr_reader: request_body
|
|
35
|
+
# The request body of the wrapped operation or the default request
|
|
36
|
+
# body for the path.
|
|
37
|
+
|
|
38
|
+
##
|
|
39
|
+
# :attr_reader: responses
|
|
40
|
+
# The responses of the wrapped operation in combination with the
|
|
41
|
+
# responses applying to all operations in the path.
|
|
42
|
+
|
|
43
|
+
##
|
|
44
|
+
# :attr_reader: security_requirements
|
|
45
|
+
# The security requirements of the wrapped operation in combination
|
|
46
|
+
# with the security requirements applying to all operations in the
|
|
47
|
+
# path or the default security requirements.
|
|
48
|
+
|
|
49
|
+
# Returns the most appropriate response for +status_code+ or +nil+ if no
|
|
50
|
+
# response matches.
|
|
51
|
+
def find_response_for(status_code)
|
|
12
52
|
status_code = Status::Code.from(status_code)
|
|
13
53
|
|
|
14
54
|
responses.find do |status, _response|
|
|
@@ -16,77 +56,78 @@ module Jsapi
|
|
|
16
56
|
end&.second
|
|
17
57
|
end
|
|
18
58
|
|
|
59
|
+
# Like +find_response_for+, except that it raises a ResponseNotFound
|
|
60
|
+
# error when no response matches.
|
|
61
|
+
def find_response_for!(status_code)
|
|
62
|
+
response = find_response_for(status_code)
|
|
63
|
+
return response if response
|
|
64
|
+
|
|
65
|
+
raise ResponseNotFound.new(self, status_code)
|
|
66
|
+
end
|
|
67
|
+
|
|
19
68
|
def full_path # :nodoc:
|
|
20
69
|
@full_path ||= super
|
|
21
70
|
end
|
|
22
71
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
72
|
+
# Returns a hash containing all +header+ parameters.
|
|
73
|
+
def header_parameters
|
|
74
|
+
@header_parameters ||= parameters.select do |_name, parameter|
|
|
75
|
+
parameter.in == 'header'
|
|
76
|
+
end
|
|
77
|
+
end
|
|
27
78
|
|
|
28
|
-
#
|
|
29
|
-
def model
|
|
79
|
+
def model # :nodoc:
|
|
30
80
|
return @model if defined? @model
|
|
31
81
|
|
|
32
|
-
@model = super ||
|
|
82
|
+
@model = super || api.common_model(full_path)
|
|
33
83
|
end
|
|
34
84
|
|
|
35
|
-
|
|
36
|
-
# :attr_reader: parameters
|
|
37
|
-
# The parameters of the wrapped operation in combination with the
|
|
38
|
-
# parameters applying to all operations in the path.
|
|
39
|
-
|
|
40
|
-
# -
|
|
41
|
-
def parameters
|
|
85
|
+
def parameters # :nodoc:
|
|
42
86
|
@parameters ||=
|
|
43
|
-
(
|
|
44
|
-
.transform_values { |parameter| Parameter.wrap(parameter,
|
|
87
|
+
(api.common_parameters(full_path)&.merge(super) || super)
|
|
88
|
+
.transform_values { |parameter| Parameter.wrap(parameter, api) }
|
|
45
89
|
end
|
|
46
90
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
91
|
+
# Returns a hash containing all +query+ parameters.
|
|
92
|
+
def query_parameters
|
|
93
|
+
@query_parameters ||= parameters.select do |_name, parameter|
|
|
94
|
+
parameter.in == 'query'
|
|
95
|
+
end
|
|
96
|
+
end
|
|
51
97
|
|
|
52
|
-
#
|
|
53
|
-
def
|
|
98
|
+
# Returns the sole +querystring+ parameter if present, otherwise +nil+.
|
|
99
|
+
def querystring_parameter
|
|
100
|
+
return @querystring_parameter if defined? @querystring_parameter
|
|
101
|
+
|
|
102
|
+
@querystring_parameter = parameters.each_value.find do |parameter|
|
|
103
|
+
parameter.in == 'querystring'
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def request_body # :nodoc:
|
|
54
108
|
return @request_body if defined? @request_body
|
|
55
109
|
|
|
56
110
|
@request_body = RequestBody.wrap(
|
|
57
|
-
|
|
58
|
-
|
|
111
|
+
super || api.common_request_body(full_path),
|
|
112
|
+
api
|
|
59
113
|
)
|
|
60
114
|
end
|
|
61
115
|
|
|
62
|
-
|
|
63
|
-
# :attr_reader: responses
|
|
64
|
-
# The responses of the wrapped operation in combination with the
|
|
65
|
-
# responses applying to all operations in the path.
|
|
66
|
-
|
|
67
|
-
# -
|
|
68
|
-
def responses
|
|
116
|
+
def responses # :nodoc:
|
|
69
117
|
@responses ||=
|
|
70
|
-
(
|
|
71
|
-
.transform_values { |response| Response.wrap(response,
|
|
118
|
+
(api.common_responses(full_path)&.merge(super) || super)
|
|
119
|
+
.transform_values { |response| Response.wrap(response, api) }
|
|
72
120
|
.sort_by { |status, _response| status }
|
|
73
121
|
.to_h
|
|
74
122
|
end
|
|
75
123
|
|
|
76
|
-
|
|
77
|
-
# :attr_reader: security_requirements
|
|
78
|
-
# The security requirements of the wrapped operation in combination
|
|
79
|
-
# with the security requirements applying to all operations in the
|
|
80
|
-
# path or the default security requirements.
|
|
81
|
-
|
|
82
|
-
# -
|
|
83
|
-
def security_requirements
|
|
124
|
+
def security_requirements # :nodoc:
|
|
84
125
|
return @security_requirements if defined? @security_requirements
|
|
85
126
|
|
|
86
127
|
@security_requirements =
|
|
87
|
-
[
|
|
88
|
-
|
|
89
|
-
|
|
128
|
+
[api.common_security_requirements(full_path), super]
|
|
129
|
+
.compact.presence&.flatten ||
|
|
130
|
+
api.default_security_requirements
|
|
90
131
|
end
|
|
91
132
|
end
|
|
92
133
|
|
|
@@ -118,8 +159,13 @@ module Jsapi
|
|
|
118
159
|
##
|
|
119
160
|
# :attr: method
|
|
120
161
|
# The HTTP method of the operation, <code>"get"</code> by default.
|
|
162
|
+
#
|
|
163
|
+
# Aliased as +http_method+.
|
|
121
164
|
attribute :method, String, default: 'get'
|
|
122
165
|
|
|
166
|
+
alias http_method method # :nodoc:
|
|
167
|
+
alias http_method= method= # :nodoc:
|
|
168
|
+
|
|
123
169
|
##
|
|
124
170
|
# :attr: model
|
|
125
171
|
# The model class to access top-level parameters by.
|
|
@@ -220,43 +266,43 @@ module Jsapi
|
|
|
220
266
|
end
|
|
221
267
|
|
|
222
268
|
# Returns a hash representing the \OpenAPI operation object.
|
|
223
|
-
def to_openapi(version,
|
|
269
|
+
def to_openapi(version, api)
|
|
224
270
|
version = OpenAPI::Version.from(version)
|
|
225
271
|
full_path = self.full_path
|
|
226
272
|
|
|
227
273
|
responses = (
|
|
228
|
-
|
|
274
|
+
api.common_responses(full_path)&.merge(self.responses) ||
|
|
229
275
|
self.responses
|
|
230
276
|
).reject do |status, response|
|
|
231
|
-
response.resolve_lazily(
|
|
277
|
+
response.resolve_lazily(api).nodoc ||
|
|
232
278
|
version == OpenAPI::V2_0 && status.is_a?(Status::Range)
|
|
233
279
|
end
|
|
234
280
|
|
|
235
281
|
with_openapi_extensions(
|
|
236
282
|
operationId: name,
|
|
237
283
|
tags:
|
|
238
|
-
[tags,
|
|
239
|
-
|
|
284
|
+
[tags, api.common_tags(full_path)]
|
|
285
|
+
.compact.flatten.uniq.presence,
|
|
240
286
|
summary: summary,
|
|
241
287
|
description: description,
|
|
242
288
|
externalDocs: external_docs&.to_openapi,
|
|
243
289
|
**if version == OpenAPI::V2_0
|
|
244
290
|
resolved_request_body =
|
|
245
|
-
(request_body ||
|
|
246
|
-
&.resolve(
|
|
291
|
+
(request_body || api.common_request_body(full_path))
|
|
292
|
+
&.resolve(api)
|
|
247
293
|
{
|
|
248
294
|
consumes:
|
|
249
295
|
[resolved_request_body&.default_media_range]
|
|
250
|
-
|
|
296
|
+
.compact.presence,
|
|
251
297
|
produces:
|
|
252
298
|
responses.values.filter_map do |response|
|
|
253
|
-
response.resolve(
|
|
299
|
+
response.resolve(api).default_media_type
|
|
254
300
|
end.uniq.sort.presence,
|
|
255
301
|
schemes: schemes.presence,
|
|
256
302
|
parameters:
|
|
257
303
|
begin
|
|
258
304
|
params = parameters.values.flat_map do |parameter|
|
|
259
|
-
parameter.to_openapi_parameters(version,
|
|
305
|
+
parameter.to_openapi_parameters(version, api)
|
|
260
306
|
end
|
|
261
307
|
if resolved_request_body
|
|
262
308
|
params << resolved_request_body.to_openapi_parameter
|
|
@@ -272,23 +318,23 @@ module Jsapi
|
|
|
272
318
|
end.presence,
|
|
273
319
|
callbacks:
|
|
274
320
|
callbacks.transform_values do |callback|
|
|
275
|
-
callback.to_openapi(version,
|
|
321
|
+
callback.to_openapi(version, api)
|
|
276
322
|
end.presence,
|
|
277
323
|
parameters:
|
|
278
324
|
parameters.values.flat_map do |parameter|
|
|
279
|
-
parameter.to_openapi_parameters(version,
|
|
325
|
+
parameter.to_openapi_parameters(version, api)
|
|
280
326
|
end,
|
|
281
327
|
requestBody: request_body&.to_openapi(version)
|
|
282
328
|
}
|
|
283
329
|
end,
|
|
284
330
|
responses:
|
|
285
331
|
responses.transform_values do |response|
|
|
286
|
-
response.to_openapi(version,
|
|
332
|
+
response.to_openapi(version, api)
|
|
287
333
|
end,
|
|
288
334
|
deprecated: deprecated?.presence,
|
|
289
335
|
security:
|
|
290
|
-
[security_requirements,
|
|
291
|
-
|
|
336
|
+
[security_requirements, api.common_security_requirements(full_path)]
|
|
337
|
+
.compact.presence&.flatten&.map(&:to_openapi)
|
|
292
338
|
)
|
|
293
339
|
end
|
|
294
340
|
end
|
|
@@ -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
|
|
6
6
|
# Specifies a parameter.
|
|
7
7
|
class Base < Model::Base
|
|
@@ -87,12 +87,12 @@ module Jsapi
|
|
|
87
87
|
end
|
|
88
88
|
|
|
89
89
|
# Returns a hash representing the \OpenAPI parameter object.
|
|
90
|
-
def to_openapi(version,
|
|
90
|
+
def to_openapi(version, api)
|
|
91
91
|
version = OpenAPI::Version.from(version)
|
|
92
92
|
|
|
93
93
|
openapi_parameter_object(
|
|
94
94
|
name,
|
|
95
|
-
schema.resolve(
|
|
95
|
+
schema.resolve(api),
|
|
96
96
|
version,
|
|
97
97
|
location: self.in,
|
|
98
98
|
content_type: content_type ||
|
|
@@ -106,31 +106,31 @@ module Jsapi
|
|
|
106
106
|
end
|
|
107
107
|
|
|
108
108
|
# Returns an array of hashes representing the \OpenAPI parameter objects.
|
|
109
|
-
def to_openapi_parameters(version,
|
|
109
|
+
def to_openapi_parameters(version, api)
|
|
110
110
|
version = OpenAPI::Version.from(version)
|
|
111
111
|
is_querystring = self.in == 'querystring'
|
|
112
|
-
schema = self.schema.resolve(
|
|
112
|
+
schema = self.schema.resolve(api)
|
|
113
113
|
|
|
114
114
|
if schema.object? && (version < OpenAPI::V3_2 || !is_querystring)
|
|
115
115
|
explode_parameter(
|
|
116
116
|
is_querystring ? nil : name,
|
|
117
117
|
schema,
|
|
118
118
|
version,
|
|
119
|
-
|
|
119
|
+
api,
|
|
120
120
|
location: is_querystring ? 'query' : self.in,
|
|
121
121
|
required: required?,
|
|
122
122
|
deprecated: deprecated?
|
|
123
123
|
)
|
|
124
124
|
else
|
|
125
|
-
[to_openapi(version,
|
|
125
|
+
[to_openapi(version, api)]
|
|
126
126
|
end.compact
|
|
127
127
|
end
|
|
128
128
|
|
|
129
129
|
private
|
|
130
130
|
|
|
131
|
-
def explode_parameter(name, schema, version,
|
|
132
|
-
schema.resolve_properties(
|
|
133
|
-
property_schema = property.schema.resolve(
|
|
131
|
+
def explode_parameter(name, schema, version, api, location:, required:, deprecated:)
|
|
132
|
+
schema.resolve_properties(api, context: :request).values.flat_map do |property|
|
|
133
|
+
property_schema = property.schema.resolve(api)
|
|
134
134
|
parameter_name = name ? "#{name}[#{property.name}]" : property.name
|
|
135
135
|
required = (required && property.required?).presence
|
|
136
136
|
deprecated = (deprecated || property_schema.deprecated?).presence
|
|
@@ -140,7 +140,7 @@ module Jsapi
|
|
|
140
140
|
parameter_name,
|
|
141
141
|
property_schema,
|
|
142
142
|
version,
|
|
143
|
-
|
|
143
|
+
api,
|
|
144
144
|
location: location,
|
|
145
145
|
required: required,
|
|
146
146
|
deprecated: deprecated
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Jsapi
|
|
4
|
-
module
|
|
4
|
+
module Definition
|
|
5
5
|
module Parameter
|
|
6
6
|
# Refers a reusable parameter.
|
|
7
7
|
class Reference < Model::Reference
|
|
8
8
|
# Returns an array of hashes representing the \OpenAPI parameter or reference objects.
|
|
9
9
|
#
|
|
10
10
|
# Raises a ReferenceError when the reference could not be resolved.
|
|
11
|
-
def to_openapi_parameters(version,
|
|
11
|
+
def to_openapi_parameters(version, api)
|
|
12
12
|
version = OpenAPI::Version.from(version)
|
|
13
|
-
parameter = resolve(
|
|
13
|
+
parameter = resolve(api)
|
|
14
14
|
|
|
15
|
-
if parameter.schema.resolve(
|
|
15
|
+
if parameter.schema.resolve(api).object?
|
|
16
16
|
# Explode referred parameter
|
|
17
|
-
parameter.to_openapi_parameters(version,
|
|
17
|
+
parameter.to_openapi_parameters(version, api)
|
|
18
18
|
else
|
|
19
19
|
# Return an array containing the reference object
|
|
20
20
|
[to_openapi(version)]
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Jsapi
|
|
4
|
-
module
|
|
4
|
+
module Definition
|
|
5
5
|
# Specifies a property
|
|
6
6
|
class Property < Model::Base
|
|
7
7
|
class Wrapper < Model::Wrapper
|
|
8
8
|
delegate :additional_properties, :default_value, :items, to: :schema
|
|
9
9
|
|
|
10
10
|
def schema
|
|
11
|
-
@schema ||= Schema.wrap(super,
|
|
11
|
+
@schema ||= Schema.wrap(super, api)
|
|
12
12
|
end
|
|
13
13
|
end
|
|
14
14
|
|