jsapi 1.4 → 2.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 (113) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jsapi/controller/actions/class_methods.rb +61 -0
  3. data/lib/jsapi/controller/actions.rb +13 -0
  4. data/lib/jsapi/controller/authentication/class_methods.rb +65 -0
  5. data/lib/jsapi/controller/authentication/credentials/api_key.rb +24 -0
  6. data/lib/jsapi/controller/authentication/credentials/http/base.rb +25 -0
  7. data/lib/jsapi/controller/authentication/credentials/http/basic.rb +34 -0
  8. data/lib/jsapi/controller/authentication/credentials/http/bearer.rb +30 -0
  9. data/lib/jsapi/controller/authentication/credentials/http.rb +5 -0
  10. data/lib/jsapi/controller/authentication/credentials.rb +38 -0
  11. data/lib/jsapi/controller/authentication.rb +70 -0
  12. data/lib/jsapi/controller/base.rb +5 -4
  13. data/lib/jsapi/controller/methods/callbacks/callback.rb +80 -0
  14. data/lib/jsapi/controller/methods/callbacks/class_methods.rb +62 -0
  15. data/lib/jsapi/controller/methods/callbacks.rb +54 -0
  16. data/lib/jsapi/controller/methods.rb +209 -116
  17. data/lib/jsapi/controller/parameters.rb +24 -20
  18. data/lib/jsapi/controller/response.rb +71 -39
  19. data/lib/jsapi/controller.rb +2 -1
  20. data/lib/jsapi/dsl/base.rb +38 -5
  21. data/lib/jsapi/dsl/class_methods.rb +2 -2
  22. data/lib/jsapi/dsl/definitions.rb +41 -27
  23. data/lib/jsapi/dsl/operation.rb +10 -109
  24. data/lib/jsapi/dsl/parameter.rb +1 -1
  25. data/lib/jsapi/dsl/path.rb +41 -18
  26. data/lib/jsapi/dsl/request_body.rb +1 -1
  27. data/lib/jsapi/dsl/response.rb +9 -6
  28. data/lib/jsapi/dsl/schema.rb +11 -5
  29. data/lib/jsapi/dsl/shared_operation_methods.rb +140 -0
  30. data/lib/jsapi/dsl.rb +1 -2
  31. data/lib/jsapi/json/array.rb +2 -2
  32. data/lib/jsapi/json/object.rb +6 -6
  33. data/lib/jsapi/json.rb +4 -6
  34. data/lib/jsapi/media/range.rb +102 -0
  35. data/lib/jsapi/media/type.rb +70 -0
  36. data/lib/jsapi/media/type_and_subtype.rb +38 -0
  37. data/lib/jsapi/media.rb +9 -0
  38. data/lib/jsapi/messages.rb +19 -0
  39. data/lib/jsapi/meta/callback/base.rb +63 -8
  40. data/lib/jsapi/meta/content.rb +59 -0
  41. data/lib/jsapi/meta/definitions.rb +299 -153
  42. data/lib/jsapi/meta/example/base.rb +41 -8
  43. data/lib/jsapi/meta/existence.rb +4 -2
  44. data/lib/jsapi/meta/header/base.rb +4 -2
  45. data/lib/jsapi/meta/info.rb +3 -1
  46. data/lib/jsapi/meta/license.rb +11 -5
  47. data/lib/jsapi/meta/model/attributes/class_methods.rb +150 -0
  48. data/lib/jsapi/meta/model/attributes/frozen_error.rb +16 -0
  49. data/lib/jsapi/meta/model/attributes/type_caster.rb +56 -0
  50. data/lib/jsapi/meta/model/attributes.rb +24 -118
  51. data/lib/jsapi/meta/model/base.rb +2 -5
  52. data/lib/jsapi/meta/model/reference.rb +46 -10
  53. data/lib/jsapi/meta/model/wrappable.rb +23 -0
  54. data/lib/jsapi/meta/model/wrapper.rb +26 -0
  55. data/lib/jsapi/meta/model.rb +2 -1
  56. data/lib/jsapi/meta/oauth_flow.rb +1 -1
  57. data/lib/jsapi/meta/openapi/extensions.rb +5 -6
  58. data/lib/jsapi/meta/openapi/version.rb +16 -4
  59. data/lib/jsapi/meta/operation.rb +177 -71
  60. data/lib/jsapi/meta/parameter/base.rb +10 -6
  61. data/lib/jsapi/meta/parameter/wrapper.rb +13 -0
  62. data/lib/jsapi/meta/parameter.rb +3 -0
  63. data/lib/jsapi/meta/path.rb +59 -13
  64. data/lib/jsapi/meta/pathname.rb +6 -3
  65. data/lib/jsapi/meta/property.rb +10 -0
  66. data/lib/jsapi/meta/request_body/base.rb +69 -32
  67. data/lib/jsapi/meta/request_body/wrapper.rb +13 -0
  68. data/lib/jsapi/meta/request_body.rb +3 -0
  69. data/lib/jsapi/meta/rescue_handler.rb +18 -17
  70. data/lib/jsapi/meta/response/base.rb +82 -58
  71. data/lib/jsapi/meta/response/reference.rb +11 -1
  72. data/lib/jsapi/meta/response/wrapper.rb +26 -0
  73. data/lib/jsapi/meta/response.rb +3 -0
  74. data/lib/jsapi/meta/schema/additional_properties.rb +8 -0
  75. data/lib/jsapi/meta/schema/array.rb +20 -8
  76. data/lib/jsapi/meta/schema/base.rb +10 -9
  77. data/lib/jsapi/meta/schema/boundary.rb +1 -0
  78. data/lib/jsapi/meta/schema/numeric.rb +26 -20
  79. data/lib/jsapi/meta/schema/object.rb +60 -44
  80. data/lib/jsapi/meta/schema/reference.rb +1 -8
  81. data/lib/jsapi/meta/schema/string.rb +12 -6
  82. data/lib/jsapi/meta/schema/wrapper.rb +31 -0
  83. data/lib/jsapi/meta/schema.rb +22 -9
  84. data/lib/jsapi/meta/security_requirement.rb +2 -2
  85. data/lib/jsapi/meta/security_scheme/api_key.rb +5 -2
  86. data/lib/jsapi/meta/security_scheme/base.rb +7 -5
  87. data/lib/jsapi/meta/security_scheme/http/basic.rb +5 -7
  88. data/lib/jsapi/meta/security_scheme/http/bearer.rb +5 -5
  89. data/lib/jsapi/meta/security_scheme/http/other.rb +1 -3
  90. data/lib/jsapi/meta/security_scheme/mutual_tls.rb +1 -3
  91. data/lib/jsapi/meta/security_scheme/oauth2.rb +18 -13
  92. data/lib/jsapi/meta/security_scheme/open_id_connect.rb +4 -4
  93. data/lib/jsapi/meta/security_scheme.rb +4 -4
  94. data/lib/jsapi/meta/server.rb +4 -2
  95. data/lib/jsapi/meta/tag.rb +9 -3
  96. data/lib/jsapi/meta.rb +2 -1
  97. data/lib/jsapi/model/base.rb +1 -1
  98. data/lib/jsapi/status/base.rb +35 -0
  99. data/lib/jsapi/status/code.rb +113 -0
  100. data/lib/jsapi/status/default.rb +16 -0
  101. data/lib/jsapi/status/range.rb +35 -0
  102. data/lib/jsapi/status.rb +37 -0
  103. data/lib/jsapi/version.rb +1 -1
  104. data/lib/jsapi.rb +3 -3
  105. metadata +36 -10
  106. data/lib/jsapi/controller/parameters_invalid.rb +0 -27
  107. data/lib/jsapi/dsl/callback.rb +0 -21
  108. data/lib/jsapi/dsl/error.rb +0 -36
  109. data/lib/jsapi/invalid_argument_error.rb +0 -12
  110. data/lib/jsapi/invalid_value_error.rb +0 -12
  111. data/lib/jsapi/invalid_value_helper.rb +0 -17
  112. data/lib/jsapi/meta/model/type_caster.rb +0 -50
  113. data/lib/jsapi/meta/schema/delegator.rb +0 -26
@@ -1,10 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'controller/parameters_invalid'
4
3
  require_relative 'controller/error'
4
+ require_relative 'controller/authentication'
5
5
  require_relative 'controller/parameters'
6
6
  require_relative 'controller/response'
7
7
  require_relative 'controller/methods'
8
+ require_relative 'controller/actions'
8
9
  require_relative 'controller/base'
9
10
 
10
11
  module Jsapi
@@ -2,6 +2,37 @@
2
2
 
3
3
  module Jsapi
4
4
  module DSL
5
+ # Raised when an error occurred while defining an API component.
6
+ class Error < StandardError
7
+
8
+ # Creates a new error. +origin+ is the innermost position at where the error occurred.
9
+ def initialize(error_or_message, origin = nil)
10
+ @path = Array(origin)
11
+ super(
12
+ if error_or_message.respond_to?(:message)
13
+ error_or_message.message
14
+ else
15
+ error_or_message
16
+ end
17
+ )
18
+ end
19
+
20
+ # Overrides <code>StandardError#message</code> to append the whole path of the position
21
+ # at where the error occurred, for example: <code>{message} (at foo / bar)</code>.
22
+ def message
23
+ message = super
24
+ return message if @path.empty?
25
+
26
+ "#{message} (at #{@path.join(' / ')})"
27
+ end
28
+
29
+ # Prepends +origin+ to the path at where the error occurred.
30
+ def prepend_origin(origin)
31
+ @path.prepend(origin) if origin.present?
32
+ self
33
+ end
34
+ end
35
+
5
36
  class Base
6
37
  def initialize(meta_model, pathname = nil, parent: nil, &block)
7
38
  @meta_model = meta_model
@@ -48,8 +79,8 @@ module Jsapi
48
79
  self.class.new(@meta_model, pathname, parent: self)
49
80
  end
50
81
 
51
- def respond_to_missing?(*args) # :nodoc:
52
- keyword?(args.first)
82
+ def respond_to_missing?(param1, *) # :nodoc:
83
+ keyword?(param1)
53
84
  end
54
85
 
55
86
  protected
@@ -59,7 +90,8 @@ module Jsapi
59
90
  private
60
91
 
61
92
  def define(*args, &block)
62
- block.call
93
+ result = block.call
94
+ result.freeze_attributes if result.respond_to?(:freeze_attributes)
63
95
  rescue Error => e
64
96
  raise e.prepend_origin(args.compact.join(' '))
65
97
  rescue StandardError => e
@@ -77,8 +109,9 @@ module Jsapi
77
109
  raise "unsupported keyword: #{name}" unless method
78
110
 
79
111
  define(name) do
80
- result = @meta_model.public_send(method, *params)
81
- Base.new(result, &block) if block
112
+ @meta_model.public_send(method, *params).tap do |result|
113
+ Base.new(result, &block) if block
114
+ end
82
115
  end
83
116
  end
84
117
 
@@ -154,8 +154,8 @@ module Jsapi
154
154
  # operation 'bar'
155
155
  # end
156
156
  #
157
- def api_path(name, &block)
158
- api_definitions { path(name, &block) }
157
+ def api_path(name, **keywords, &block)
158
+ api_definitions { path(name, **keywords, &block) }
159
159
  end
160
160
 
161
161
  # Defines a reusable request body.
@@ -22,8 +22,9 @@ module Jsapi
22
22
  # See Meta::Definitions#callbacks for further information.
23
23
  def callback(name, **keywords, &block)
24
24
  define('callback', name.inspect) do
25
- callback = @meta_model.add_callback(name, keywords)
26
- Callback.new(callback, &block) if block
25
+ @meta_model.add_callback(name, keywords).tap do |callback|
26
+ Base.new(callback, &block) if block
27
+ end
27
28
  end
28
29
  end
29
30
 
@@ -34,8 +35,9 @@ module Jsapi
34
35
  # See Meta::Definitions#defaults for further information.
35
36
  def default(type, **keywords, &block)
36
37
  define('default', type.inspect) do
37
- default = @meta_model.add_default(type, keywords)
38
- Base.new(default, &block) if block
38
+ @meta_model.add_default(type, keywords).tap do |default|
39
+ Base.new(default, &block) if block
40
+ end
39
41
  end
40
42
  end
41
43
 
@@ -46,8 +48,9 @@ module Jsapi
46
48
  # See Meta::Definitions#examples for further information.
47
49
  def example(name, **keywords, &block)
48
50
  define('example', name.inspect) do
49
- example = @meta_model.add_example(name, keywords)
50
- Base.new(example, &block) if block
51
+ @meta_model.add_example(name, keywords).tap do |example|
52
+ Base.new(example, &block) if block
53
+ end
51
54
  end
52
55
  end
53
56
 
@@ -74,8 +77,9 @@ module Jsapi
74
77
  # See Meta::Definitions#headers for further information.
75
78
  def header(name, **keywords, &block)
76
79
  define('header', name.inspect) do
77
- header = @meta_model.add_header(name, keywords)
78
- Base.new(header, &block) if block
80
+ @meta_model.add_header(name, keywords).tap do |header|
81
+ Base.new(header, &block) if block
82
+ end
79
83
  end
80
84
  end
81
85
 
@@ -106,8 +110,9 @@ module Jsapi
106
110
  # See Meta::Definitions#links for further information.
107
111
  def link(name, **keywords, &block)
108
112
  define('link', name.inspect) do
109
- link = @meta_model.add_link(name, keywords)
110
- Base.new(link, &block) if block
113
+ @meta_model.add_link(name, keywords).tap do |link|
114
+ Base.new(link, &block) if block
115
+ end
111
116
  end
112
117
  end
113
118
 
@@ -138,8 +143,9 @@ module Jsapi
138
143
  # See Meta::Definitions#operations for further information.
139
144
  def operation(name = nil, **keywords, &block)
140
145
  define('operation', name&.inspect) do
141
- operation_model = @meta_model.add_operation(name, keywords)
142
- Operation.new(operation_model, &block) if block
146
+ @meta_model.add_operation(name, keywords).tap do |operation_model|
147
+ Operation.new(operation_model, &block) if block
148
+ end
143
149
  end
144
150
  end
145
151
 
@@ -150,8 +156,9 @@ module Jsapi
150
156
  # See Meta::Definitions#parameters for further information.
151
157
  def parameter(name, **keywords, &block)
152
158
  define('parameter', name.inspect) do
153
- parameter_model = @meta_model.add_parameter(name, keywords)
154
- Parameter.new(parameter_model, &block) if block
159
+ @meta_model.add_parameter(name, keywords).tap do |parameter_model|
160
+ Parameter.new(parameter_model, &block) if block
161
+ end
155
162
  end
156
163
  end
157
164
 
@@ -162,10 +169,11 @@ module Jsapi
162
169
  # operation 'bar'
163
170
  # end
164
171
  #
165
- def path(name = nil, &block)
172
+ def path(name = nil, **keywords, &block)
166
173
  define('path', name&.inspect) do
167
- path_model = @meta_model.add_path(name)
168
- Path.new(path_model, &block) if block
174
+ @meta_model.add_path(name, keywords).tap do |path_model|
175
+ Path.new(path_model, &block) if block
176
+ end
169
177
  end
170
178
  end
171
179
 
@@ -176,19 +184,22 @@ module Jsapi
176
184
  # See Meta::Definitions#request_bodies for further information.
177
185
  def request_body(name, **keywords, &block)
178
186
  define('request_body', name.inspect) do
179
- request_body_model = @meta_model.add_request_body(name, keywords)
180
- RequestBody.new(request_body_model, &block) if block
187
+ @meta_model.add_request_body(name, keywords).tap do |request_body_model|
188
+ RequestBody.new(request_body_model, &block) if block
189
+ end
181
190
  end
182
191
  end
183
192
 
184
- # Specifies the HTTP status code of an error response rendered when an exception of
193
+ # Specifies the status code of a response to be produced when an error of
185
194
  # any of +klasses+ has been raised.
186
195
  #
187
196
  # rescue_from Jsapi::Controller::ParametersInvalid, with: 400
188
197
  #
189
198
  def rescue_from(*klasses, with: nil)
190
199
  klasses.each do |klass|
191
- @meta_model.add_rescue_handler({ error_class: klass, status: with })
200
+ @meta_model.add_rescue_handler(
201
+ { error_class: klass, status_code: with }
202
+ )
192
203
  end
193
204
  end
194
205
 
@@ -201,8 +212,9 @@ module Jsapi
201
212
  # See Meta::Definitions#responses for further information.
202
213
  def response(name, **keywords, &block)
203
214
  define('response', name.inspect) do
204
- response_model = @meta_model.add_response(name, keywords)
205
- Response.new(response_model, &block) if block
215
+ @meta_model.add_response(name, keywords).tap do |response_model|
216
+ Response.new(response_model, &block) if block
217
+ end
206
218
  end
207
219
  end
208
220
 
@@ -215,8 +227,9 @@ module Jsapi
215
227
  # See Meta::Definitions#schemas for further information.
216
228
  def schema(name, **keywords, &block)
217
229
  define('schema', name.inspect) do
218
- schema_model = @meta_model.add_schema(name, keywords)
219
- Schema.new(schema_model, &block) if block
230
+ @meta_model.add_schema(name, keywords).tap do |schema_model|
231
+ Schema.new(schema_model, &block) if block
232
+ end
220
233
  end
221
234
  end
222
235
 
@@ -247,8 +260,9 @@ module Jsapi
247
260
  # See Meta::Definitions#security_schemes for further information.
248
261
  def security_scheme(name, **keywords, &block)
249
262
  define('security_scheme', name.inspect) do
250
- security_scheme = @meta_model.add_security_scheme(name, keywords)
251
- Base.new(security_scheme, &block) if block
263
+ @meta_model.add_security_scheme(name, keywords).tap do |security_scheme|
264
+ Base.new(security_scheme, &block) if block
265
+ end
252
266
  end
253
267
  end
254
268
 
@@ -4,6 +4,7 @@ module Jsapi
4
4
  module DSL
5
5
  # Used to define an API operation.
6
6
  class Operation < Base
7
+ include SharedOperationMethods
7
8
 
8
9
  # Specifies a callback.
9
10
  #
@@ -26,15 +27,16 @@ module Jsapi
26
27
  name = keywords[:ref] if name.nil?
27
28
  keywords = { ref: name } unless keywords.any? || block
28
29
 
29
- callback_model = @meta_model.add_callback(name, keywords)
30
- Callback.new(callback_model, &block) if block
30
+ @meta_model.add_callback(name, keywords).tap do |callback_model|
31
+ Base.new(callback_model, &block) if block
32
+ end
31
33
  end
32
34
  end
33
35
 
34
36
  ##
35
37
  # :method: deprecated
36
38
  # :args: arg
37
- # Specifies whether or not the operation is deprecated.
39
+ # Specifies whether the operation is marked as deprecated.
38
40
  #
39
41
  # deprecated true
40
42
 
@@ -61,116 +63,11 @@ module Jsapi
61
63
  keyword(:method, arg)
62
64
  end
63
65
 
64
- # Defines the model class to access top-level parameters by.
65
- #
66
- # model Foo do
67
- # def bar
68
- # # ...
69
- # end
70
- # end
71
- #
72
- # +klass+ can be any subclass of Model::Base. If block is given, an anonymous
73
- # class is created that inherits either from +klass+ or Model::Base.
74
- def model(klass = nil, &block)
75
- if block
76
- klass = Class.new(klass || Model::Base)
77
- klass.class_eval(&block)
78
- end
79
- @meta_model.model = klass
80
- end
81
-
82
- # Specifies a parameter
83
- #
84
- # parameter 'foo', type: 'string'
85
- #
86
- # parameter 'foo', type: 'object' do
87
- # property 'bar', type: 'string'
88
- # end
89
- #
90
- # Refers a resuable parameter if the `:ref` keyword is specified.
91
- #
92
- # parameter ref: 'foo'
93
- #
94
- # Refers the reusable parameter with the same name if neither any keywords
95
- # nor a block is specified.
96
- #
97
- # parameter 'foo'
98
- #
99
- # See Meta::Operation#parameters for further information.
100
- def parameter(name = nil, **keywords, &block)
101
- define('parameter', name&.inspect) do
102
- name = keywords[:ref] if name.nil?
103
- keywords = { ref: name } unless keywords.any? || block
104
-
105
- parameter_model = @meta_model.add_parameter(name, keywords)
106
- Parameter.new(parameter_model, &block) if block
107
- end
108
- end
109
-
110
66
  ##
111
67
  # :method: path
112
68
  # :args: arg
113
69
  # Specifies the relative path of the operation.
114
70
 
115
- # Specifies the request body.
116
- #
117
- # request_body type: 'object' do
118
- # property 'foo', type: 'string'
119
- # end
120
- #
121
- # Refers a resuable request body if the `:ref` keyword is specified.
122
- #
123
- # request_body ref: 'foo'
124
- #
125
- # Refers the reusable request body with the same name if neither any
126
- # keywords nor a block is specified.
127
- #
128
- # request_body 'foo'
129
- #
130
- # See Meta::Operation#request_body for further information.
131
- def request_body(**keywords, &block)
132
- define('request body') do
133
- @meta_model.request_body = keywords
134
- RequestBody.new(@meta_model.request_body, &block) if block
135
- end
136
- end
137
-
138
- # Specifies a response.
139
- #
140
- # response 200, type: 'object' do
141
- # property 'foo', type: 'string'
142
- # end
143
- #
144
- # The default status is <code>"default"</code>.
145
- #
146
- # Refers a resuable response if the `:ref` keyword is specified.
147
- #
148
- # response 200, ref: 'foo'
149
- #
150
- # Refers the reusable response with the same name if neither any keywords
151
- # nor a block is specified.
152
- #
153
- # response 'foo'
154
- #
155
- # Raises an Error if name is specified together with keywords or a block.
156
- #
157
- # See Meta::Operation#responses for further information.
158
- def response(status_or_name = nil, name = nil, **keywords, &block)
159
- define('response', status_or_name&.inspect) do
160
- raise Error, "name can't be specified together with keywords " \
161
- 'or a block' if name && (keywords.any? || block)
162
-
163
- if keywords.any? || block
164
- status = status_or_name
165
- else
166
- status = status_or_name if name
167
- keywords = { ref: name || status_or_name }
168
- end
169
- response_model = @meta_model.add_response(status, keywords)
170
- Response.new(response_model, &block) if block
171
- end
172
- end
173
-
174
71
  ##
175
72
  # :method: security_requirement
176
73
  # :args: **keywords, &block
@@ -182,10 +79,14 @@ module Jsapi
182
79
  #
183
80
  # See Meta::Operation#security_requirements for further information.
184
81
 
82
+ # :method: server
83
+ # :args: arg
84
+ # Specifies a server providing the operation.
85
+
185
86
  ##
186
87
  # :method: summary
187
88
  # :args: arg
188
- # Specifies the short summary of the operation.
89
+ # Specifies the short description of the operation.
189
90
 
190
91
  ##
191
92
  # :method: tag
@@ -9,7 +9,7 @@ module Jsapi
9
9
  ##
10
10
  # :method: deprecated
11
11
  # :args: arg
12
- # Specifies whether or not the parameter is deprecated.
12
+ # Specifies whether the parameter is marked as deprecated.
13
13
  #
14
14
  # deprecated true
15
15
 
@@ -3,7 +3,14 @@
3
3
  module Jsapi
4
4
  module DSL
5
5
  class Path < Base
6
- # Specifies an operation within the current path.
6
+ include SharedOperationMethods
7
+
8
+ ##
9
+ # :method: description
10
+ # :args: arg
11
+ # Specifies the common description for all operations in this path.
12
+
13
+ # Specifies an operation within this path.
7
14
  #
8
15
  # operation 'foo' do
9
16
  # parameter 'bar', type: 'string'
@@ -14,30 +21,46 @@ module Jsapi
14
21
  #
15
22
  def operation(name = nil, **keywords, &block)
16
23
  define('operation', name&.inspect) do
17
- operation_model = @meta_model.owner.add_operation(name, @meta_model.name, keywords)
18
- Operation.new(operation_model, &block) if block
19
- end
20
- end
21
-
22
- # Specifies a parameter applicable for all operations in this path.
23
- #
24
- # parameter 'foo', type: 'string'
25
- #
26
- # See Meta::Path#parameters for further information.
27
- def parameter(name, **keywords, &block)
28
- define('parameter', name.inspect) do
29
- parameter_model = @meta_model.add_parameter(name, keywords)
30
- Parameter.new(parameter_model, &block) if block
24
+ @meta_model.owner.add_operation(name, @meta_model.name, keywords)
25
+ .tap do |operation_model|
26
+ Operation.new(operation_model, &block) if block
27
+ end
31
28
  end
32
29
  end
33
30
 
34
31
  # Specifies a nested path.
35
- def path(name = nil, &block)
32
+ def path(name = nil, **keywords, &block)
36
33
  define('path', name&.inspect) do
37
- path_model = @meta_model.owner.add_path(@meta_model.name + name.to_s)
38
- Path.new(path_model, &block) if block
34
+ name = @meta_model.name + name.to_s
35
+
36
+ @meta_model.owner.add_path(name, keywords).tap do |path_model|
37
+ Path.new(path_model, &block) if block
38
+ end
39
39
  end
40
40
  end
41
+
42
+ # :method: server
43
+ # :args: arg
44
+ # Specifies a server providing all operations in this path.
45
+
46
+ ##
47
+ # :method: summary
48
+ # :args: arg
49
+ # Specifies the common summary for all operations in this path.
50
+
51
+ ##
52
+ # :method: tag
53
+ # :args: name
54
+ # Adds a tag.
55
+ #
56
+ # tag 'foo'
57
+
58
+ ##
59
+ # :method: tags
60
+ # :args: names
61
+ # Specifies all tags at once.
62
+ #
63
+ # tags %w[foo bar]
41
64
  end
42
65
  end
43
66
  end
@@ -9,7 +9,7 @@ module Jsapi
9
9
  ##
10
10
  # :method: deprecated
11
11
  # :args: arg
12
- # Specifies whether or not the request body is deprecated.
12
+ # Specifies whether the request body is marked as deprecated.
13
13
  #
14
14
  # deprecated true
15
15
 
@@ -9,7 +9,7 @@ module Jsapi
9
9
  ##
10
10
  # :method: deprecated
11
11
  # :args: arg
12
- # Specifies whether or not the response is deprecated.
12
+ # Specifies whether the response is marked as deprecated.
13
13
  #
14
14
  # deprecated true
15
15
 
@@ -37,8 +37,9 @@ module Jsapi
37
37
  name = keywords[:ref] if name.nil?
38
38
  keywords = { ref: name } unless keywords.any? || block
39
39
 
40
- header_model = @meta_model.add_header(name, keywords)
41
- Base.new(header_model, &block) if block
40
+ @meta_model.add_header(name, keywords).tap do |header_model|
41
+ Base.new(header_model, &block) if block
42
+ end
42
43
  end
43
44
  end
44
45
 
@@ -60,15 +61,17 @@ module Jsapi
60
61
  name = keywords[:ref] if name.nil?
61
62
  keywords = { ref: name } unless keywords.any? || block
62
63
 
63
- link_model = @meta_model.add_link(name, keywords)
64
- Base.new(link_model, &block) if block
64
+ @meta_model.add_link(name, keywords).tap do |link_model|
65
+ Base.new(link_model, &block) if block
66
+ end
65
67
  end
66
68
  end
67
69
 
68
70
  ##
69
71
  # :method: locale
70
72
  # :args: arg
71
- # Specifies the locale to be used when producing a response.
73
+ # Specifies the locale to be used instead of the default locale when
74
+ # producing a response.
72
75
  #
73
76
  # locale :en
74
77
  end
@@ -40,7 +40,7 @@ module Jsapi
40
40
  ##
41
41
  # :method: deprecated
42
42
  # :args: arg
43
- # Specifies whether or not the schema is deprecated.
43
+ # Specifies whether the schema is marked as deprecated.
44
44
  #
45
45
  # deprecated true
46
46
 
@@ -102,8 +102,13 @@ module Jsapi
102
102
  raise Error, "items isn't supported for '#{@meta_model.type}'"
103
103
  end
104
104
 
105
- @meta_model.items = keywords
106
- Schema.new(@meta_model.items, &block) if block
105
+ define do
106
+ @meta_model.items = keywords
107
+
108
+ @meta_model.items.tap do |items|
109
+ Schema.new(items, &block) if block
110
+ end
111
+ end
107
112
  end
108
113
 
109
114
  ##
@@ -209,8 +214,9 @@ module Jsapi
209
214
  raise Error, "property isn't supported for '#{@meta_model.type}'"
210
215
  end
211
216
 
212
- property_model = @meta_model.add_property(name, keywords)
213
- Schema.new(property_model, &block) if block
217
+ @meta_model.add_property(name, keywords).tap do |property_model|
218
+ Schema.new(property_model, &block) if block
219
+ end
214
220
  end
215
221
  end
216
222