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.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jsapi/client/base.rb +182 -0
  3. data/lib/jsapi/client/exceptions.rb +45 -0
  4. data/lib/jsapi/client/request.rb +204 -0
  5. data/lib/jsapi/client/response.rb +120 -0
  6. data/lib/jsapi/client/session/base.rb +61 -0
  7. data/lib/jsapi/client/session/logger.rb +52 -0
  8. data/lib/jsapi/client/session/single_request.rb +16 -0
  9. data/lib/jsapi/client/session/test/class_methods.rb +49 -0
  10. data/lib/jsapi/client/session/test/response.rb +56 -0
  11. data/lib/jsapi/client/session/test/spy.rb +43 -0
  12. data/lib/jsapi/client/session/test.rb +17 -0
  13. data/lib/jsapi/client/session.rb +6 -0
  14. data/lib/jsapi/client.rb +7 -0
  15. data/lib/jsapi/configuration.rb +2 -2
  16. data/lib/jsapi/controller/authentication/credentials/http/bearer.rb +5 -12
  17. data/lib/jsapi/controller/authentication/credentials.rb +4 -4
  18. data/lib/jsapi/controller/authentication.rb +3 -3
  19. data/lib/jsapi/controller/methods.rb +43 -77
  20. data/lib/jsapi/controller/parameters.rb +6 -6
  21. data/lib/jsapi/controller/response.rb +7 -7
  22. data/lib/jsapi/{meta/definitions.rb → definition/api.rb} +62 -40
  23. data/lib/jsapi/{meta → definition}/callable/symbol_evaluator.rb +1 -1
  24. data/lib/jsapi/{meta → definition}/callable/symbol_sequence_evaluator.rb +1 -1
  25. data/lib/jsapi/{meta → definition}/callable.rb +1 -1
  26. data/lib/jsapi/{meta → definition}/callback/base.rb +5 -5
  27. data/lib/jsapi/{meta → definition}/callback/reference.rb +1 -1
  28. data/lib/jsapi/{meta → definition}/callback.rb +1 -1
  29. data/lib/jsapi/{meta → definition}/contact.rb +1 -1
  30. data/lib/jsapi/{meta → definition}/content.rb +11 -11
  31. data/lib/jsapi/{meta → definition}/defaults.rb +1 -1
  32. data/lib/jsapi/{meta → definition}/example/base.rb +1 -1
  33. data/lib/jsapi/{meta → definition}/example/builder.rb +4 -4
  34. data/lib/jsapi/{meta → definition}/example/reference.rb +1 -1
  35. data/lib/jsapi/{meta → definition}/example.rb +1 -1
  36. data/lib/jsapi/{meta → definition}/existence.rb +1 -1
  37. data/lib/jsapi/{meta → definition}/external_documentation.rb +1 -1
  38. data/lib/jsapi/{meta → definition}/header/base.rb +1 -1
  39. data/lib/jsapi/{meta → definition}/header/reference.rb +1 -1
  40. data/lib/jsapi/{meta → definition}/header.rb +1 -1
  41. data/lib/jsapi/{meta → definition}/info.rb +1 -1
  42. data/lib/jsapi/{meta → definition}/license.rb +1 -1
  43. data/lib/jsapi/{meta → definition}/link/base.rb +1 -1
  44. data/lib/jsapi/{meta → definition}/link/reference.rb +1 -1
  45. data/lib/jsapi/{meta → definition}/link.rb +1 -1
  46. data/lib/jsapi/{meta → definition}/model/attributes/class_methods.rb +1 -1
  47. data/lib/jsapi/{meta → definition}/model/attributes/frozen_error.rb +1 -1
  48. data/lib/jsapi/{meta → definition}/model/attributes/type_caster.rb +2 -2
  49. data/lib/jsapi/{meta → definition}/model/attributes.rb +1 -1
  50. data/lib/jsapi/{meta → definition}/model/base.rb +1 -1
  51. data/lib/jsapi/{meta → definition}/model/reference.rb +11 -11
  52. data/lib/jsapi/{meta → definition}/model/wrappable.rb +3 -3
  53. data/lib/jsapi/{meta → definition}/model/wrapper.rb +5 -5
  54. data/lib/jsapi/{meta → definition}/oauth_flow.rb +1 -1
  55. data/lib/jsapi/{meta → definition}/openapi/extensions.rb +1 -1
  56. data/lib/jsapi/{meta → definition}/openapi/path_item.rb +5 -5
  57. data/lib/jsapi/{meta → definition}/openapi/version.rb +2 -2
  58. data/lib/jsapi/{meta → definition}/openapi.rb +1 -1
  59. data/lib/jsapi/{meta → definition}/operation.rb +108 -62
  60. data/lib/jsapi/{meta → definition}/parameter/base.rb +11 -11
  61. data/lib/jsapi/{meta → definition}/parameter/reference.rb +5 -5
  62. data/lib/jsapi/{meta → definition}/parameter/wrapper.rb +2 -2
  63. data/lib/jsapi/{meta → definition}/parameter.rb +1 -1
  64. data/lib/jsapi/{meta → definition}/path.rb +1 -1
  65. data/lib/jsapi/{meta → definition}/pathname.rb +1 -1
  66. data/lib/jsapi/{meta → definition}/property.rb +2 -2
  67. data/lib/jsapi/{meta → definition}/reference_error.rb +1 -1
  68. data/lib/jsapi/{meta → definition}/request_body/base.rb +1 -1
  69. data/lib/jsapi/{meta → definition}/request_body/reference.rb +1 -1
  70. data/lib/jsapi/{meta → definition}/request_body/wrapper.rb +2 -2
  71. data/lib/jsapi/{meta → definition}/request_body.rb +1 -1
  72. data/lib/jsapi/{meta → definition}/rescue_handler.rb +1 -1
  73. data/lib/jsapi/{meta → definition}/response/base.rb +4 -4
  74. data/lib/jsapi/{meta → definition}/response/reference.rb +1 -1
  75. data/lib/jsapi/{meta → definition}/response/wrapper.rb +17 -5
  76. data/lib/jsapi/{meta → definition}/response.rb +1 -1
  77. data/lib/jsapi/{meta → definition}/schema/additional_properties.rb +2 -2
  78. data/lib/jsapi/{meta → definition}/schema/array.rb +2 -2
  79. data/lib/jsapi/{meta → definition}/schema/base.rb +1 -1
  80. data/lib/jsapi/{meta → definition}/schema/boolean.rb +1 -1
  81. data/lib/jsapi/{meta → definition}/schema/boundary.rb +1 -1
  82. data/lib/jsapi/{meta → definition}/schema/conversion.rb +1 -1
  83. data/lib/jsapi/{meta → definition}/schema/discriminator.rb +1 -1
  84. data/lib/jsapi/{meta → definition}/schema/integer.rb +1 -1
  85. data/lib/jsapi/{meta → definition}/schema/number.rb +1 -1
  86. data/lib/jsapi/{meta → definition}/schema/numeric.rb +1 -1
  87. data/lib/jsapi/{meta → definition}/schema/object.rb +13 -13
  88. data/lib/jsapi/{meta → definition}/schema/reference.rb +1 -1
  89. data/lib/jsapi/{meta → definition}/schema/string.rb +1 -1
  90. data/lib/jsapi/{meta → definition}/schema/validation/base.rb +1 -1
  91. data/lib/jsapi/{meta → definition}/schema/validation/enum.rb +1 -1
  92. data/lib/jsapi/{meta → definition}/schema/validation/max_items.rb +1 -1
  93. data/lib/jsapi/{meta → definition}/schema/validation/max_length.rb +1 -1
  94. data/lib/jsapi/{meta → definition}/schema/validation/maximum.rb +1 -1
  95. data/lib/jsapi/{meta → definition}/schema/validation/min_items.rb +1 -1
  96. data/lib/jsapi/{meta → definition}/schema/validation/min_length.rb +1 -1
  97. data/lib/jsapi/{meta → definition}/schema/validation/minimum.rb +1 -1
  98. data/lib/jsapi/{meta → definition}/schema/validation/multiple_of.rb +1 -1
  99. data/lib/jsapi/{meta → definition}/schema/validation/pattern.rb +1 -1
  100. data/lib/jsapi/{meta → definition}/schema/wrapper.rb +18 -4
  101. data/lib/jsapi/{meta → definition}/schema.rb +5 -5
  102. data/lib/jsapi/{meta → definition}/security_requirement.rb +1 -1
  103. data/lib/jsapi/{meta → definition}/security_scheme/api_key.rb +1 -1
  104. data/lib/jsapi/{meta → definition}/security_scheme/base.rb +1 -1
  105. data/lib/jsapi/{meta → definition}/security_scheme/http/basic.rb +1 -1
  106. data/lib/jsapi/{meta → definition}/security_scheme/http/bearer.rb +1 -1
  107. data/lib/jsapi/{meta → definition}/security_scheme/http/other.rb +1 -1
  108. data/lib/jsapi/{meta → definition}/security_scheme/http.rb +1 -1
  109. data/lib/jsapi/{meta → definition}/security_scheme/mutual_tls.rb +1 -1
  110. data/lib/jsapi/{meta → definition}/security_scheme/oauth2.rb +1 -1
  111. data/lib/jsapi/{meta → definition}/security_scheme/open_id_connect.rb +1 -1
  112. data/lib/jsapi/{meta → definition}/security_scheme.rb +1 -1
  113. data/lib/jsapi/{meta → definition}/server.rb +24 -1
  114. data/lib/jsapi/{meta → definition}/server_variable.rb +1 -1
  115. data/lib/jsapi/{meta → definition}/tag.rb +1 -1
  116. data/lib/jsapi/definition.rb +33 -0
  117. data/lib/jsapi/dsl/{definitions.rb → api.rb} +48 -48
  118. data/lib/jsapi/dsl/base.rb +7 -7
  119. data/lib/jsapi/dsl/class_methods.rb +34 -32
  120. data/lib/jsapi/dsl/examples.rb +1 -1
  121. data/lib/jsapi/dsl/operation.rb +9 -7
  122. data/lib/jsapi/dsl/parameter.rb +1 -1
  123. data/lib/jsapi/dsl/path.rb +8 -6
  124. data/lib/jsapi/dsl/response.rb +5 -5
  125. data/lib/jsapi/dsl/schema.rb +17 -17
  126. data/lib/jsapi/dsl/shared_operation_methods.rb +11 -26
  127. data/lib/jsapi/dsl.rb +2 -2
  128. data/lib/jsapi/model/errors.rb +3 -3
  129. data/lib/jsapi/status/code.rb +20 -0
  130. data/lib/jsapi/support/messages.rb +27 -0
  131. data/lib/jsapi/support.rb +3 -0
  132. data/lib/jsapi/version.rb +1 -1
  133. data/lib/jsapi.rb +3 -3
  134. metadata +115 -102
  135. data/lib/jsapi/jsonify_error.rb +0 -17
  136. data/lib/jsapi/messages.rb +0 -19
  137. data/lib/jsapi/meta.rb +0 -38
  138. /data/lib/jsapi/{meta → definition}/model.rb +0 -0
  139. /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 Meta
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, definitions)
9
+ def initialize(reference, api)
10
10
  @reference = reference
11
- @definitions = definitions
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(@definitions, deep: false)
28
- .resolve_lazily(@definitions)
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 +definitions+.
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(definitions, deep: true)
73
- object = definitions.send("find_#{self.class.component_type}", ref)
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(definitions, deep: true) : object
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(definitions)
83
- Resolver.new(self, definitions)
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 Meta
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, definitions|
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, definitions)
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 Meta
4
+ module Definition
5
5
  module Model
6
6
  # Wraps a meta model
7
7
  class Wrapper < SimpleDelegator
8
- attr_reader :definitions
8
+ attr_reader :api
9
9
 
10
- def initialize(model, definitions)
11
- super(model.resolve(definitions))
12
- @definitions = definitions
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 Meta
4
+ module Definition
5
5
  # Represents an OAuth flow object.
6
6
  class OAuthFlow < Model::Base
7
7
  include OpenAPI::Extensions
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jsapi
4
- module Meta
4
+ module Definition
5
5
  module OpenAPI
6
6
  module Extensions
7
7
  def self.included(base) # :nodoc:
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jsapi
4
- module Meta
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, definitions)
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, definitions)
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, definitions)
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, definitions)
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 Meta
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.0'
63
+ '3.2.1'
64
64
  else
65
65
  "#{major}.#{minor}"
66
66
  end
@@ -5,7 +5,7 @@ require_relative 'openapi/version'
5
5
  require_relative 'openapi/path_item'
6
6
 
7
7
  module Jsapi
8
- module Meta
8
+ module Definition
9
9
  module OpenAPI
10
10
  V2_0 = Version.new(2, 0)
11
11
  V3_0 = Version.new(3, 0)
@@ -1,14 +1,54 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jsapi
4
- module Meta
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
- # Returns the most appropriate response for +status_code+.
11
- def find_response(status_code)
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
- # :attr_reader: model
25
- # The model class of the wrapped operation or the default model class
26
- # for the path.
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 || definitions.common_model(full_path)
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
- (definitions.common_parameters(full_path)&.merge(super) || super)
44
- .transform_values { |parameter| Parameter.wrap(parameter, definitions) }
87
+ (api.common_parameters(full_path)&.merge(super) || super)
88
+ .transform_values { |parameter| Parameter.wrap(parameter, api) }
45
89
  end
46
90
 
47
- ##
48
- # :attr_reader: request_body
49
- # The request body of the wrapped operation or the default request
50
- # body for the path.
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 request_body
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
- (super || definitions.common_request_body(full_path)),
58
- definitions
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
- (definitions.common_responses(full_path)&.merge(super) || super)
71
- .transform_values { |response| Response.wrap(response, definitions) }
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
- [definitions.common_security_requirements(full_path), super]
88
- .compact.presence&.flatten ||
89
- definitions.default_security_requirements
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, definitions)
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
- definitions.common_responses(full_path)&.merge(self.responses) ||
274
+ api.common_responses(full_path)&.merge(self.responses) ||
229
275
  self.responses
230
276
  ).reject do |status, response|
231
- response.resolve_lazily(definitions).nodoc ||
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, definitions.common_tags(full_path)]
239
- .compact.flatten.uniq.presence,
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 || definitions.common_request_body(full_path))
246
- &.resolve(definitions)
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
- .compact.presence,
296
+ .compact.presence,
251
297
  produces:
252
298
  responses.values.filter_map do |response|
253
- response.resolve(definitions).default_media_type
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, definitions)
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, definitions)
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, definitions)
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, definitions)
332
+ response.to_openapi(version, api)
287
333
  end,
288
334
  deprecated: deprecated?.presence,
289
335
  security:
290
- [security_requirements, definitions.common_security_requirements(full_path)]
291
- .compact.presence&.flatten&.map(&:to_openapi)
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 Meta
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, definitions)
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(definitions),
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, definitions)
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(definitions)
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
- definitions,
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, definitions)]
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, definitions, location:, required:, deprecated:)
132
- schema.resolve_properties(definitions, context: :request).values.flat_map do |property|
133
- property_schema = property.schema.resolve(definitions)
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
- definitions,
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 Meta
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, definitions)
11
+ def to_openapi_parameters(version, api)
12
12
  version = OpenAPI::Version.from(version)
13
- parameter = resolve(definitions)
13
+ parameter = resolve(api)
14
14
 
15
- if parameter.schema.resolve(definitions).object?
15
+ if parameter.schema.resolve(api).object?
16
16
  # Explode referred parameter
17
- parameter.to_openapi_parameters(version, definitions)
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,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jsapi
4
- module Meta
4
+ module Definition
5
5
  module Parameter
6
6
  class Wrapper < Model::Wrapper
7
7
  def schema
8
- @schema ||= Schema.wrap(super, definitions)
8
+ @schema ||= Schema.wrap(super, api)
9
9
  end
10
10
  end
11
11
  end
@@ -5,7 +5,7 @@ require_relative 'parameter/reference'
5
5
  require_relative 'parameter/wrapper'
6
6
 
7
7
  module Jsapi
8
- module Meta
8
+ module Definition
9
9
  module Parameter
10
10
  include Model::Wrappable
11
11
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jsapi
4
- module Meta
4
+ module Definition
5
5
  # Specifies a path.
6
6
  class Path < Model::Base
7
7
  ##
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jsapi
4
- module Meta
4
+ module Definition
5
5
  # Represents a relative path name.
6
6
  class Pathname
7
7
  class << self
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jsapi
4
- module Meta
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, definitions)
11
+ @schema ||= Schema.wrap(super, api)
12
12
  end
13
13
  end
14
14
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jsapi
4
- module Meta
4
+ module Definition
5
5
  # Raised when a reference can't be resolved.
6
6
  class ReferenceError < StandardError
7
7
  def initialize(reference)
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jsapi
4
- module Meta
4
+ module Definition
5
5
  module RequestBody
6
6
  # Specifies a request body.
7
7
  class Base < Model::Base
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jsapi
4
- module Meta
4
+ module Definition
5
5
  module RequestBody
6
6
  # Refers a reusable request body.
7
7
  class Reference < Model::Reference; end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Jsapi
4
- module Meta
4
+ module Definition
5
5
  module RequestBody
6
6
  class Wrapper < Model::Wrapper
7
7
  def content_for(media_type)
8
- Content.wrap(super, definitions)
8
+ Content.wrap(super, api)
9
9
  end
10
10
  end
11
11
  end