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,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 server.
6
6
  class Server < Model::Base
7
7
  include OpenAPI::Extensions
@@ -39,6 +39,29 @@ module Jsapi
39
39
  variables: variables.transform_values(&:to_openapi).presence
40
40
  )
41
41
  end
42
+
43
+ # Builds the URL for +variables+.
44
+ def url_for(variables)
45
+ variables = variables&.with_indifferent_access || {}
46
+
47
+ url&.gsub(/\{\w+\}/) do |match|
48
+ name = match[1..-2]
49
+ value = variables[name]
50
+
51
+ server_variable = variable(name)
52
+ next value if server_variable.nil?
53
+ next server_variable.default if value.nil?
54
+
55
+ valid_values = server_variable.enum.presence
56
+ next value unless valid_values&.exclude?(value)
57
+
58
+ raise ArgumentError, Support::Messages.invalid_value(
59
+ name: name,
60
+ value: value,
61
+ valid_values: valid_values
62
+ )
63
+ end
64
+ end
42
65
  end
43
66
  end
44
67
  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
  # Specifies a server variable.
6
6
  class ServerVariable < 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
  # Specifies a tag.
6
6
  class Tag < Model::Base
7
7
  include OpenAPI::Extensions
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'definition/reference_error'
4
+ require_relative 'definition/callable'
5
+ require_relative 'definition/existence'
6
+ require_relative 'definition/openapi'
7
+ require_relative 'definition/model'
8
+ require_relative 'definition/defaults'
9
+ require_relative 'definition/example'
10
+ require_relative 'definition/external_documentation'
11
+ require_relative 'definition/tag'
12
+ require_relative 'definition/server_variable'
13
+ require_relative 'definition/server'
14
+ require_relative 'definition/callback'
15
+ require_relative 'definition/contact'
16
+ require_relative 'definition/license'
17
+ require_relative 'definition/info'
18
+ require_relative 'definition/header'
19
+ require_relative 'definition/oauth_flow'
20
+ require_relative 'definition/security_scheme'
21
+ require_relative 'definition/security_requirement'
22
+ require_relative 'definition/link'
23
+ require_relative 'definition/property'
24
+ require_relative 'definition/schema'
25
+ require_relative 'definition/content'
26
+ require_relative 'definition/request_body'
27
+ require_relative 'definition/parameter'
28
+ require_relative 'definition/pathname'
29
+ require_relative 'definition/response'
30
+ require_relative 'definition/operation'
31
+ require_relative 'definition/path'
32
+ require_relative 'definition/rescue_handler'
33
+ require_relative 'definition/api'
@@ -2,16 +2,16 @@
2
2
 
3
3
  module Jsapi
4
4
  module DSL
5
- # Used to define top-level API components.
6
- class Definitions < Base
5
+ # Used to define an \API.
6
+ class API < Base
7
7
  ##
8
8
  # :method: base_path
9
9
  # :args: arg
10
- # Specifies the base path of the API.
10
+ # Specifies the base path of the \API.
11
11
  #
12
12
  # base_path '/foo'
13
13
  #
14
- # See Meta::Definitions#base_path for further information.
14
+ # See Definition::API#base_path for further information.
15
15
 
16
16
  # Specifies a reusable callback.
17
17
  #
@@ -19,10 +19,10 @@ module Jsapi
19
19
  # operation '{$request.query.foo}', path: '/bar'
20
20
  # end
21
21
  #
22
- # See Meta::Definitions#callbacks for further information.
22
+ # See Definition::API#callbacks for further information.
23
23
  def callback(name, **keywords, &block)
24
24
  define('callback', name.inspect) do
25
- @meta_model.add_callback(name, keywords).tap do |callback|
25
+ @definition.add_callback(name, keywords).tap do |callback|
26
26
  Base.new(callback, &block) if block
27
27
  end
28
28
  end
@@ -32,10 +32,10 @@ module Jsapi
32
32
  #
33
33
  # default 'array', within_requests: [], within_responses: []
34
34
  #
35
- # See Meta::Definitions#defaults for further information.
35
+ # See Definition::API#defaults for further information.
36
36
  def default(type, **keywords, &block)
37
37
  define('default', type.inspect) do
38
- @meta_model.add_default(type, keywords).tap do |default|
38
+ @definition.add_default(type, keywords).tap do |default|
39
39
  Base.new(default, &block) if block
40
40
  end
41
41
  end
@@ -45,10 +45,10 @@ module Jsapi
45
45
  #
46
46
  # example '/foo', value: 'bar'
47
47
  #
48
- # See Meta::Definitions#examples for further information.
48
+ # See Definition::API#examples for further information.
49
49
  def example(name, **keywords, &block)
50
50
  define('example', name.inspect) do
51
- @meta_model.add_example(name, keywords).tap do |example|
51
+ @definition.add_example(name, keywords).tap do |example|
52
52
  Base.new(example, &block) if block
53
53
  end
54
54
  end
@@ -61,12 +61,12 @@ module Jsapi
61
61
  #
62
62
  # external_docs url: 'https://foo.bar'
63
63
  #
64
- # See Meta::Definitions#external_docs for further information.
64
+ # See Definition::API#external_docs for further information.
65
65
 
66
- # Includes API definitions from +klasses+.
66
+ # Includes \API components from +klasses+.
67
67
  def include(*klasses)
68
68
  klasses.each do |klass|
69
- @meta_model.include(klass.api_definitions)
69
+ @definition.include(klass.api_definitions)
70
70
  end
71
71
  end
72
72
 
@@ -74,10 +74,10 @@ module Jsapi
74
74
  #
75
75
  # header 'foo', type: 'string'
76
76
  #
77
- # See Meta::Definitions#headers for further information.
77
+ # See Definition::API#headers for further information.
78
78
  def header(name, **keywords, &block)
79
79
  define('header', name.inspect) do
80
- @meta_model.add_header(name, keywords).tap do |header|
80
+ @definition.add_header(name, keywords).tap do |header|
81
81
  Base.new(header, &block) if block
82
82
  end
83
83
  end
@@ -86,31 +86,31 @@ module Jsapi
86
86
  ##
87
87
  # :method: host
88
88
  # :args: arg
89
- # Specifies the host serving the API.
89
+ # Specifies the host serving the \API.
90
90
  #
91
91
  # host 'foo.bar'
92
92
  #
93
- # See Meta::Definitions#host for further information.
93
+ # See Definition::API#host for further information.
94
94
 
95
95
  ##
96
96
  # :method: info
97
97
  # :args: **keywords, &block
98
- # Specifies general information about the API.
98
+ # Specifies general information about the \API.
99
99
  #
100
100
  # info title: 'foo', version: 1 do
101
101
  # contact name: 'bar'
102
102
  # end
103
103
  #
104
- # See Meta::Definitions#info for further information.
104
+ # See Definition::API#info for further information.
105
105
 
106
106
  # Specifies a reusable link.
107
107
  #
108
108
  # link 'foo', operation_id: 'bar'
109
109
  #
110
- # See Meta::Definitions#links for further information.
110
+ # See Definition::API#links for further information.
111
111
  def link(name, **keywords, &block)
112
112
  define('link', name.inspect) do
113
- @meta_model.add_link(name, keywords).tap do |link|
113
+ @definition.add_link(name, keywords).tap do |link|
114
114
  Base.new(link, &block) if block
115
115
  end
116
116
  end
@@ -125,7 +125,7 @@ module Jsapi
125
125
  # end
126
126
  def on_rescue(method = nil, &block)
127
127
  define('on_rescue') do
128
- @meta_model.add_on_rescue(method || block)
128
+ @definition.add_on_rescue(method || block)
129
129
  end
130
130
  end
131
131
 
@@ -140,11 +140,11 @@ module Jsapi
140
140
  #
141
141
  # +name+ can be +nil+ if the controller handles one operation only.
142
142
  #
143
- # See Meta::Definitions#operations for further information.
143
+ # See Definition::API#operations for further information.
144
144
  def operation(name = nil, **keywords, &block)
145
145
  define('operation', name&.inspect) do
146
- @meta_model.add_operation(name, keywords).tap do |operation_model|
147
- Operation.new(operation_model, &block) if block
146
+ @definition.add_operation(name, keywords).tap do |operation_definition|
147
+ Operation.new(operation_definition, &block) if block
148
148
  end
149
149
  end
150
150
  end
@@ -153,11 +153,11 @@ module Jsapi
153
153
  #
154
154
  # parameter 'foo', type: 'string'
155
155
  #
156
- # See Meta::Definitions#parameters for further information.
156
+ # See Definition::API#parameters for further information.
157
157
  def parameter(name, **keywords, &block)
158
158
  define('parameter', name.inspect) do
159
- @meta_model.add_parameter(name, keywords).tap do |parameter_model|
160
- Parameter.new(parameter_model, &block) if block
159
+ @definition.add_parameter(name, keywords).tap do |parameter_definition|
160
+ Parameter.new(parameter_definition, &block) if block
161
161
  end
162
162
  end
163
163
  end
@@ -171,8 +171,8 @@ module Jsapi
171
171
  #
172
172
  def path(name = nil, **keywords, &block)
173
173
  define('path', name&.inspect) do
174
- @meta_model.add_path(name, keywords).tap do |path_model|
175
- Path.new(path_model, &block) if block
174
+ @definition.add_path(name, keywords).tap do |path_definition|
175
+ Path.new(path_definition, &block) if block
176
176
  end
177
177
  end
178
178
  end
@@ -181,11 +181,11 @@ module Jsapi
181
181
  #
182
182
  # request_body 'foo', type: 'string'
183
183
  #
184
- # See Meta::Definitions#request_bodies for further information.
184
+ # See Definition::API#request_bodies for further information.
185
185
  def request_body(name, **keywords, &block)
186
186
  define('request_body', name.inspect) do
187
- @meta_model.add_request_body(name, keywords).tap do |request_body_model|
188
- RequestBody.new(request_body_model, &block) if block
187
+ @definition.add_request_body(name, keywords).tap do |request_body_definition|
188
+ RequestBody.new(request_body_definition, &block) if block
189
189
  end
190
190
  end
191
191
  end
@@ -197,7 +197,7 @@ module Jsapi
197
197
  #
198
198
  def rescue_from(*klasses, with: nil)
199
199
  klasses.each do |klass|
200
- @meta_model.add_rescue_handler(
200
+ @definition.add_rescue_handler(
201
201
  { error_class: klass, status_code: with }
202
202
  )
203
203
  end
@@ -209,11 +209,11 @@ module Jsapi
209
209
  # property 'bar', type: 'string'
210
210
  # end
211
211
  #
212
- # See Meta::Definitions#responses for further information.
212
+ # See Definition::API#responses for further information.
213
213
  def response(name, **keywords, &block)
214
214
  define('response', name.inspect) do
215
- @meta_model.add_response(name, keywords).tap do |response_model|
216
- Response.new(response_model, &block) if block
215
+ @definition.add_response(name, keywords).tap do |response_definition|
216
+ Response.new(response_definition, &block) if block
217
217
  end
218
218
  end
219
219
  end
@@ -224,11 +224,11 @@ module Jsapi
224
224
  # property 'bar', type: 'string'
225
225
  # end
226
226
  #
227
- # See Meta::Definitions#schemas for further information.
227
+ # See Definition::API#schemas for further information.
228
228
  def schema(name, **keywords, &block)
229
229
  define('schema', name.inspect) do
230
- @meta_model.add_schema(name, keywords).tap do |schema_model|
231
- Schema.new(schema_model, &block) if block
230
+ @definition.add_schema(name, keywords).tap do |schema_definition|
231
+ Schema.new(schema_definition, &block) if block
232
232
  end
233
233
  end
234
234
  end
@@ -236,11 +236,11 @@ module Jsapi
236
236
  ##
237
237
  # :method: scheme
238
238
  # :args: arg
239
- # Specifies a URI scheme supported by the API.
239
+ # Specifies a URI scheme supported by the \API.
240
240
  #
241
241
  # scheme 'https'
242
242
  #
243
- # See Meta::Definitions#schemes for further information.
243
+ # See Definition::API#schemes for further information.
244
244
 
245
245
  ##
246
246
  # :method: security_requirement
@@ -251,16 +251,16 @@ module Jsapi
251
251
  # scheme 'basic_auth'
252
252
  # end
253
253
  #
254
- # See Meta::Definitions#security_requirements for further information.
254
+ # See Definition::API#security_requirements for further information.
255
255
 
256
256
  # Specifies a security scheme.
257
257
  #
258
258
  # security_scheme 'basic_auth', type: 'http', scheme: 'basic'
259
259
  #
260
- # See Meta::Definitions#security_schemes for further information.
260
+ # See Definition::API#security_schemes for further information.
261
261
  def security_scheme(name, **keywords, &block)
262
262
  define('security_scheme', name.inspect) do
263
- @meta_model.add_security_scheme(name, keywords).tap do |security_scheme|
263
+ @definition.add_security_scheme(name, keywords).tap do |security_scheme|
264
264
  Base.new(security_scheme, &block) if block
265
265
  end
266
266
  end
@@ -269,11 +269,11 @@ module Jsapi
269
269
  ##
270
270
  # :method: server
271
271
  # :args: **keywords, &block
272
- # Specifies a server providing the API.
272
+ # Specifies a server providing the \API.
273
273
  #
274
274
  # server url: 'https://foo.bar/foo'
275
275
  #
276
- # See Meta::Definitions#servers for further information.
276
+ # See Definition::API#servers for further information.
277
277
 
278
278
  ##
279
279
  # :method: tag
@@ -282,7 +282,7 @@ module Jsapi
282
282
  #
283
283
  # tag name: 'foo', description: 'description of foo'
284
284
  #
285
- # See Meta::Definitions#tags for further information.
285
+ # See Definition::API#tags for further information.
286
286
  end
287
287
  end
288
288
  end
@@ -34,8 +34,8 @@ module Jsapi
34
34
  end
35
35
 
36
36
  class Base
37
- def initialize(meta_model, pathname = nil, parent: nil, &block)
38
- @meta_model = meta_model
37
+ def initialize(definition, pathname = nil, parent: nil, &block)
38
+ @definition = definition
39
39
  @pathname = pathname
40
40
  @parent = parent
41
41
 
@@ -55,7 +55,7 @@ module Jsapi
55
55
 
56
56
  # Evaluate block
57
57
  if block
58
- if meta_model.reference?
58
+ if definition.reference?
59
59
  raise Error, "reference can't be specified together with a block"
60
60
  end
61
61
 
@@ -68,7 +68,7 @@ module Jsapi
68
68
  raise ArgumentError, "file name can't be blank" if filename.blank?
69
69
 
70
70
  pathname = Jsapi.configuration.pathname("#{filename}.rb")
71
- self.class.new(@meta_model, pathname, parent: self)
71
+ self.class.new(@definition, pathname, parent: self)
72
72
  end
73
73
 
74
74
  # Imports the file named +filename+ relative to the current file's path.
@@ -76,7 +76,7 @@ module Jsapi
76
76
  raise ArgumentError, "file name can't be blank" if filename.blank?
77
77
 
78
78
  pathname = (@pathname&.parent || Jsapi.configuration.pathname) + "#{filename}.rb"
79
- self.class.new(@meta_model, pathname, parent: self)
79
+ self.class.new(@definition, pathname, parent: self)
80
80
  end
81
81
 
82
82
  def respond_to_missing?(param1, *) # :nodoc:
@@ -105,7 +105,7 @@ module Jsapi
105
105
 
106
106
  def find_method(name)
107
107
  ["#{name}=", "add_#{name}"].find do |method|
108
- @meta_model.respond_to?(method)
108
+ @definition.respond_to?(method)
109
109
  end
110
110
  end
111
111
 
@@ -114,7 +114,7 @@ module Jsapi
114
114
  raise "unsupported keyword: #{name}" unless method
115
115
 
116
116
  define(name) do
117
- @meta_model.public_send(method, *params).tap do |result|
117
+ @definition.public_send(method, *params).tap do |result|
118
118
  Base.new(result, &block) if block
119
119
  end
120
120
  end
@@ -3,7 +3,35 @@
3
3
  module Jsapi
4
4
  module DSL
5
5
  module ClassMethods
6
- # Specifies the base path of the API.
6
+ # Returns the \API definition associated with the current class. Defines it,
7
+ # if keywords or a block are passed.
8
+ #
9
+ # api base_path: '/foo' do
10
+ # operation 'bar'
11
+ # end
12
+ def api(**keywords, &block)
13
+ unless defined? @api_definition
14
+ @api_definition = Definition::API.new(
15
+ owner: self,
16
+ parent: superclass.try(:api_definitions)
17
+ )
18
+ if (name = try(:name))
19
+ pathname = Jsapi.configuration.pathname(
20
+ name.deconstantize.split('::').map(&:underscore),
21
+ "#{name.demodulize.delete_suffix('Controller').underscore}.rb"
22
+ )
23
+ API.new(@api_definition, pathname) if pathname&.file?
24
+ end
25
+ end
26
+ @api_definition.merge!(keywords) if keywords.any?
27
+ API.new(@api_definition, &block) if block
28
+
29
+ @api_definition
30
+ end
31
+
32
+ alias api_definitions api
33
+
34
+ # Specifies the base path of the \API.
7
35
  #
8
36
  # api_base_path '/foo'
9
37
  #
@@ -29,32 +57,6 @@ module Jsapi
29
57
  api_definitions { default(type, **keywords, &block) }
30
58
  end
31
59
 
32
- # Returns the API definitions associated with the current class. Adds additional
33
- # definitions when any keywords or a block is specified.
34
- #
35
- # api_definitions base_path: '/foo' do
36
- # operation 'bar'
37
- # end
38
- def api_definitions(**keywords, &block)
39
- unless defined? @api_definitions
40
- @api_definitions = Meta::Definitions.new(
41
- owner: self,
42
- parent: superclass.try(:api_definitions)
43
- )
44
- if (name = try(:name))
45
- pathname = Jsapi.configuration.pathname(
46
- name.deconstantize.split('::').map(&:underscore),
47
- "#{name.demodulize.delete_suffix('Controller').underscore}.rb"
48
- )
49
- Definitions.new(@api_definitions, pathname) if pathname&.file?
50
- end
51
- end
52
- @api_definitions.merge!(keywords) if keywords.any?
53
- Definitions.new(@api_definitions, &block) if block
54
-
55
- @api_definitions
56
- end
57
-
58
60
  # Specifies a reusable example.
59
61
  #
60
62
  # example 'foo', value: 'bar'
@@ -79,7 +81,7 @@ module Jsapi
79
81
  api_definitions { header(name, **keywords, &block) }
80
82
  end
81
83
 
82
- # Specifies the host serving the API.
84
+ # Specifies the host serving the \API.
83
85
  #
84
86
  # api_host 'foo.bar'
85
87
  #
@@ -92,12 +94,12 @@ module Jsapi
92
94
  api_definitions { import(filename) }
93
95
  end
94
96
 
95
- # Includes API definitions from +klasses+.
97
+ # Includes \API components from +klasses+.
96
98
  def api_include(*klasses)
97
99
  api_definitions { include(*klasses) }
98
100
  end
99
101
 
100
- # Specifies general information about the API.
102
+ # Specifies general information about the \API.
101
103
  #
102
104
  # api_info title: 'Foo', version: '1' do
103
105
  # contact name: 'bar'
@@ -193,7 +195,7 @@ module Jsapi
193
195
  api_definitions { schema(name, **keywords, &block) }
194
196
  end
195
197
 
196
- # Specifies a URI scheme supported by the API.
198
+ # Specifies a URI scheme supported by the \API.
197
199
  #
198
200
  # api_scheme 'https'
199
201
  #
@@ -219,7 +221,7 @@ module Jsapi
219
221
  api_definitions { security_scheme(name, **keywords, &block) }
220
222
  end
221
223
 
222
- # Specifies a server providing the API.
224
+ # Specifies a server providing the \API.
223
225
  #
224
226
  # api_server url: 'https://foo.bar/foo'
225
227
  #
@@ -21,7 +21,7 @@ module Jsapi
21
21
  keywords = { value: name_or_value }
22
22
  end
23
23
 
24
- example = @meta_model.add_example(name, keywords)
24
+ example = @definition.add_example(name, keywords)
25
25
  Base.new(example, &block) if block
26
26
  end
27
27
  end
@@ -21,14 +21,14 @@ module Jsapi
21
21
  #
22
22
  # callback 'foo'
23
23
  #
24
- # See Meta::Operation#callbacks for further information.
24
+ # See Definition::Operation#callbacks for further information.
25
25
  def callback(name = nil, **keywords, &block)
26
26
  define('callback', name&.inspect) do
27
27
  name = keywords[:ref] if name.nil?
28
28
  keywords = { ref: name } unless keywords.any? || block
29
29
 
30
- @meta_model.add_callback(name, keywords).tap do |callback_model|
31
- Base.new(callback_model, &block) if block
30
+ @definition.add_callback(name, keywords).tap do |callback_definition|
31
+ Base.new(callback_definition, &block) if block
32
32
  end
33
33
  end
34
34
  end
@@ -47,18 +47,20 @@ module Jsapi
47
47
  #
48
48
  # external_docs url: 'https://foo.bar/docs'
49
49
  #
50
- # See Meta::Operation#external_docs for further information.
50
+ # See Definition::Operation#external_docs for further information.
51
51
 
52
52
  ##
53
53
  # :method: description
54
54
  # :args: arg
55
55
  # Specifies the description of the operation.
56
56
 
57
- # Specifies the HTTP verb of the operation.
57
+ # Specifies the HTTP method of the operation.
58
58
  #
59
59
  # method 'post'
60
60
  #
61
- # See Meta::Operation#method for further information.
61
+ # See Definition::Operation#method for further information.
62
+ #
63
+ # Aliased as +http_method+.
62
64
  def method(arg)
63
65
  keyword(:method, arg)
64
66
  end
@@ -77,7 +79,7 @@ module Jsapi
77
79
  # scheme 'basic_auth'
78
80
  # end
79
81
  #
80
- # See Meta::Operation#security_requirements for further information.
82
+ # See Definition::Operation#security_requirements for further information.
81
83
 
82
84
  # :method: server
83
85
  # :args: arg
@@ -23,7 +23,7 @@ module Jsapi
23
23
  # :args: location
24
24
  # Specifies the location of the parameter.
25
25
  #
26
- # See Meta::Parameter::Model#in for further information.
26
+ # See Definition::Parameter::Model#in for further information.
27
27
  end
28
28
  end
29
29
  end
@@ -21,9 +21,11 @@ module Jsapi
21
21
  #
22
22
  def operation(name = nil, **keywords, &block)
23
23
  define('operation', name&.inspect) do
24
- @meta_model.owner.add_operation(name, @meta_model.name, keywords)
25
- .tap do |operation_model|
26
- Operation.new(operation_model, &block) if block
24
+ @definition
25
+ .owner
26
+ .add_operation(name, @definition.name, keywords)
27
+ .tap do |operation_definition|
28
+ Operation.new(operation_definition, &block) if block
27
29
  end
28
30
  end
29
31
  end
@@ -31,10 +33,10 @@ module Jsapi
31
33
  # Specifies a nested path.
32
34
  def path(name = nil, **keywords, &block)
33
35
  define('path', name&.inspect) do
34
- name = @meta_model.name + name.to_s
36
+ name = @definition.name + name.to_s
35
37
 
36
- @meta_model.owner.add_path(name, keywords).tap do |path_model|
37
- Path.new(path_model, &block) if block
38
+ @definition.owner.add_path(name, keywords).tap do |path_definition|
39
+ Path.new(path_definition, &block) if block
38
40
  end
39
41
  end
40
42
  end
@@ -31,14 +31,14 @@ module Jsapi
31
31
  #
32
32
  # header 'x_foo'
33
33
  #
34
- # See Meta::Response::Model#headers for further information.
34
+ # See Definition::Response::Model#headers for further information.
35
35
  def header(name = nil, **keywords, &block)
36
36
  define('header', name&.inspect) do
37
37
  name = keywords[:ref] if name.nil?
38
38
  keywords = { ref: name } unless keywords.any? || block
39
39
 
40
- @meta_model.add_header(name, keywords).tap do |header_model|
41
- Base.new(header_model, &block) if block
40
+ @definition.add_header(name, keywords).tap do |header_definition|
41
+ Base.new(header_definition, &block) if block
42
42
  end
43
43
  end
44
44
  end
@@ -61,8 +61,8 @@ module Jsapi
61
61
  name = keywords[:ref] if name.nil?
62
62
  keywords = { ref: name } unless keywords.any? || block
63
63
 
64
- @meta_model.add_link(name, keywords).tap do |link_model|
65
- Base.new(link_model, &block) if block
64
+ @definition.add_link(name, keywords).tap do |link_definition|
65
+ Base.new(link_definition, &block) if block
66
66
  end
67
67
  end
68
68
  end