jsapi 0.7.3 → 0.9.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 (114) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jsapi/controller/{error_result.rb → error.rb} +1 -1
  3. data/lib/jsapi/controller/methods.rb +49 -38
  4. data/lib/jsapi/controller/parameters.rb +4 -2
  5. data/lib/jsapi/controller/response.rb +82 -64
  6. data/lib/jsapi/controller.rb +1 -1
  7. data/lib/jsapi/dsl/base.rb +55 -0
  8. data/lib/jsapi/dsl/callback.rb +21 -0
  9. data/lib/jsapi/dsl/class_methods.rb +116 -10
  10. data/lib/jsapi/dsl/definitions.rb +173 -33
  11. data/lib/jsapi/dsl/examples.rb +30 -0
  12. data/lib/jsapi/dsl/operation.rb +60 -32
  13. data/lib/jsapi/dsl/parameter.rb +2 -2
  14. data/lib/jsapi/dsl/request_body.rb +2 -2
  15. data/lib/jsapi/dsl/response.rb +35 -11
  16. data/lib/jsapi/dsl/schema.rb +16 -16
  17. data/lib/jsapi/dsl.rb +4 -4
  18. data/lib/jsapi/{helpers/invalid_value_helper.rb → invalid_value_helper.rb} +1 -1
  19. data/lib/jsapi/json/array.rb +7 -7
  20. data/lib/jsapi/json/object.rb +6 -6
  21. data/lib/jsapi/json.rb +4 -4
  22. data/lib/jsapi/meta/base/attributes.rb +21 -19
  23. data/lib/jsapi/meta/base/model.rb +15 -7
  24. data/lib/jsapi/meta/callback/model.rb +34 -0
  25. data/lib/jsapi/meta/callback/reference.rb +14 -0
  26. data/lib/jsapi/meta/callback.rb +19 -0
  27. data/lib/jsapi/meta/contact.rb +30 -0
  28. data/lib/jsapi/meta/defaults.rb +2 -2
  29. data/lib/jsapi/meta/definitions.rb +230 -124
  30. data/lib/jsapi/meta/example/model.rb +43 -0
  31. data/lib/jsapi/meta/example/reference.rb +14 -0
  32. data/lib/jsapi/meta/example.rb +19 -0
  33. data/lib/jsapi/meta/external_documentation.rb +25 -0
  34. data/lib/jsapi/meta/header/model.rb +81 -0
  35. data/lib/jsapi/meta/header/reference.rb +14 -0
  36. data/lib/jsapi/meta/header.rb +19 -0
  37. data/lib/jsapi/meta/info.rb +52 -0
  38. data/lib/jsapi/meta/license.rb +25 -0
  39. data/lib/jsapi/meta/link/model.rb +48 -0
  40. data/lib/jsapi/meta/link/reference.rb +14 -0
  41. data/lib/jsapi/meta/link.rb +19 -0
  42. data/lib/jsapi/meta/oauth_flow.rb +52 -0
  43. data/lib/jsapi/meta/openapi.rb +0 -28
  44. data/lib/jsapi/meta/operation.rb +19 -18
  45. data/lib/jsapi/meta/parameter/model.rb +6 -4
  46. data/lib/jsapi/meta/parameter/reference.rb +6 -4
  47. data/lib/jsapi/meta/parameter/to_openapi.rb +13 -0
  48. data/lib/jsapi/meta/parameter.rb +2 -1
  49. data/lib/jsapi/meta/property.rb +1 -1
  50. data/lib/jsapi/meta/request_body/model.rb +6 -5
  51. data/lib/jsapi/meta/request_body.rb +1 -1
  52. data/lib/jsapi/meta/response/model.rb +16 -13
  53. data/lib/jsapi/meta/response.rb +1 -1
  54. data/lib/jsapi/meta/schema/array.rb +1 -1
  55. data/lib/jsapi/meta/schema/base.rb +5 -5
  56. data/lib/jsapi/meta/schema/discriminator.rb +2 -2
  57. data/lib/jsapi/meta/schema/object.rb +3 -3
  58. data/lib/jsapi/meta/schema/reference.rb +1 -1
  59. data/lib/jsapi/meta/schema.rb +2 -2
  60. data/lib/jsapi/meta/security_requirement.rb +25 -0
  61. data/lib/jsapi/meta/security_scheme/api_key.rb +38 -0
  62. data/lib/jsapi/meta/security_scheme/base.rb +14 -0
  63. data/lib/jsapi/meta/security_scheme/http/basic.rb +34 -0
  64. data/lib/jsapi/meta/security_scheme/http/bearer.rb +36 -0
  65. data/lib/jsapi/meta/security_scheme/http/other.rb +36 -0
  66. data/lib/jsapi/meta/security_scheme/http.rb +29 -0
  67. data/lib/jsapi/meta/security_scheme/oauth2.rb +44 -0
  68. data/lib/jsapi/meta/security_scheme/open_id_connect.rb +32 -0
  69. data/lib/jsapi/meta/security_scheme.rb +49 -0
  70. data/lib/jsapi/meta/server.rb +34 -0
  71. data/lib/jsapi/meta/server_variable.rb +34 -0
  72. data/lib/jsapi/meta/tag.rb +34 -0
  73. data/lib/jsapi/meta.rb +15 -1
  74. data/lib/jsapi/model/base.rb +5 -5
  75. data/lib/jsapi/version.rb +1 -1
  76. data/lib/jsapi.rb +1 -1
  77. metadata +40 -44
  78. data/lib/jsapi/dsl/node.rb +0 -62
  79. data/lib/jsapi/dsl/openapi/callback.rb +0 -23
  80. data/lib/jsapi/dsl/openapi/callbacks.rb +0 -34
  81. data/lib/jsapi/dsl/openapi/examples.rb +0 -32
  82. data/lib/jsapi/dsl/openapi/root.rb +0 -126
  83. data/lib/jsapi/dsl/openapi.rb +0 -6
  84. data/lib/jsapi/meta/openapi/callback/model.rb +0 -34
  85. data/lib/jsapi/meta/openapi/callback/reference.rb +0 -16
  86. data/lib/jsapi/meta/openapi/callback.rb +0 -21
  87. data/lib/jsapi/meta/openapi/contact.rb +0 -32
  88. data/lib/jsapi/meta/openapi/example/model.rb +0 -44
  89. data/lib/jsapi/meta/openapi/example/reference.rb +0 -16
  90. data/lib/jsapi/meta/openapi/example.rb +0 -21
  91. data/lib/jsapi/meta/openapi/external_documentation.rb +0 -27
  92. data/lib/jsapi/meta/openapi/header/model.rb +0 -82
  93. data/lib/jsapi/meta/openapi/header/reference.rb +0 -16
  94. data/lib/jsapi/meta/openapi/header.rb +0 -21
  95. data/lib/jsapi/meta/openapi/info.rb +0 -54
  96. data/lib/jsapi/meta/openapi/license.rb +0 -27
  97. data/lib/jsapi/meta/openapi/link/model.rb +0 -50
  98. data/lib/jsapi/meta/openapi/link/reference.rb +0 -16
  99. data/lib/jsapi/meta/openapi/link.rb +0 -21
  100. data/lib/jsapi/meta/openapi/oauth_flow.rb +0 -52
  101. data/lib/jsapi/meta/openapi/root.rb +0 -132
  102. data/lib/jsapi/meta/openapi/security_requirement.rb +0 -27
  103. data/lib/jsapi/meta/openapi/security_scheme/api_key.rb +0 -40
  104. data/lib/jsapi/meta/openapi/security_scheme/base.rb +0 -16
  105. data/lib/jsapi/meta/openapi/security_scheme/http/basic.rb +0 -36
  106. data/lib/jsapi/meta/openapi/security_scheme/http/bearer.rb +0 -39
  107. data/lib/jsapi/meta/openapi/security_scheme/http/other.rb +0 -39
  108. data/lib/jsapi/meta/openapi/security_scheme/http.rb +0 -31
  109. data/lib/jsapi/meta/openapi/security_scheme/oauth2.rb +0 -46
  110. data/lib/jsapi/meta/openapi/security_scheme/open_id_connect.rb +0 -34
  111. data/lib/jsapi/meta/openapi/security_scheme.rb +0 -51
  112. data/lib/jsapi/meta/openapi/server.rb +0 -36
  113. data/lib/jsapi/meta/openapi/server_variable.rb +0 -36
  114. data/lib/jsapi/meta/openapi/tag.rb +0 -36
@@ -3,46 +3,128 @@
3
3
  module Jsapi
4
4
  module DSL
5
5
  # Used to define top-level API components.
6
- class Definitions < Node
6
+ class Definitions < Base
7
+ ##
8
+ # :method: base_path
9
+ # :args: arg
10
+ # Specifies the base path of the API.
11
+ #
12
+ # base_path '/foo'
13
+ #
14
+ # See Meta::Definitions#base_path for further information.
15
+
16
+ # Specifies a reusable callback.
17
+ #
18
+ # callback 'foo' do
19
+ # operation '{$request.query.foo}', path: '/bar'
20
+ # end
21
+ #
22
+ # See Meta::Definitions#callbacks for further information.
23
+ def callback(name, **keywords, &block)
24
+ define('callback', name.inspect) do
25
+ callback = @meta_model.add_callback(name, keywords)
26
+ Callback.new(callback, &block) if block
27
+ end
28
+ end
7
29
 
8
30
  # Specifies the general default values for +type+.
9
31
  #
10
- # default 'array', read: [], write: []
32
+ # default 'array', within_requests: [], within_responses: []
11
33
  #
34
+ # See Meta::Definitions#defaults for further information.
12
35
  def default(type, **keywords, &block)
13
- _define('default', type.inspect) do
14
- default = _meta_model.add_default(type, keywords)
15
- Node.new(default, &block) if block
36
+ define('default', type.inspect) do
37
+ default = @meta_model.add_default(type, keywords)
38
+ Base.new(default, &block) if block
16
39
  end
17
40
  end
18
41
 
42
+ # Specifies a reusable example.
43
+ #
44
+ # example '/foo', value: 'bar'
45
+ #
46
+ # See Meta::Definitions#examples for further information.
47
+ def example(name, **keywords, &block)
48
+ define('example', name.inspect) do
49
+ example = @meta_model.add_example(name, keywords)
50
+ Base.new(example, &block) if block
51
+ end
52
+ end
53
+
54
+ ##
55
+ # :method: external_docs
56
+ # :args: **keywords, &block
57
+ # Specifies the external documentation.
58
+ #
59
+ # external_docs url: 'https://foo.bar'
60
+ #
61
+ # See Meta::Definitions#external_docs for further information.
62
+
19
63
  # Includes API definitions from +klasses+.
20
64
  def include(*klasses)
21
65
  klasses.each do |klass|
22
- _meta_model.include(klass.api_definitions)
66
+ @meta_model.include(klass.api_definitions)
23
67
  end
24
68
  end
25
69
 
26
- # Registers a callback to be called when rescuing an exception.
27
- def on_rescue(method = nil, &block)
28
- _define('on_rescue') do
29
- _meta_model.add_on_rescue(method || block)
70
+ # Specifies a reusable header.
71
+ #
72
+ # header 'foo', type: 'string'
73
+ #
74
+ # See Meta::Definitions#headers for further information.
75
+ def header(name, **keywords, &block)
76
+ define('header', name.inspect) do
77
+ header = @meta_model.add_header(name, keywords)
78
+ Base.new(header, &block) if block
79
+ end
80
+ end
81
+
82
+ ##
83
+ # :method: host
84
+ # :args: arg
85
+ # Specifies the host serving the API.
86
+ #
87
+ # host 'foo.bar'
88
+ #
89
+ # See Meta::Definitions#host for further information.
90
+
91
+ ##
92
+ # :method: info
93
+ # :args: **keywords, &block
94
+ # Specifies general information about the API.
95
+ #
96
+ # info title: 'foo', version: 1 do
97
+ # contact name: 'bar'
98
+ # end
99
+ #
100
+ # See Meta::Definitions#info for further information.
101
+
102
+ # Specifies a reusable link.
103
+ #
104
+ # link 'foo', operation_id: 'bar'
105
+ #
106
+ # See Meta::Definitions#links for further information.
107
+ def link(name, **keywords, &block)
108
+ define('link', name.inspect) do
109
+ link = @meta_model.add_link(name, keywords)
110
+ Base.new(link, &block) if block
30
111
  end
31
112
  end
32
113
 
33
- # Defines the root of an \OpenAPI document.
114
+ # Registers a callback to be called when rescuing an exception.
115
+ #
116
+ # on_rescue :foo
34
117
  #
35
- # openapi do
36
- # info title: 'Foo', version: '1'
118
+ # on_rescue do |error|
119
+ # # ...
37
120
  # end
38
- def openapi(**keywords, &block)
39
- _define('openapi') do
40
- _meta_model.openapi = keywords
41
- OpenAPI::Root.new(_meta_model.openapi, &block) if block
121
+ def on_rescue(method = nil, &block)
122
+ define('on_rescue') do
123
+ @meta_model.add_on_rescue(method || block)
42
124
  end
43
125
  end
44
126
 
45
- # Defines an operation.
127
+ # Specifies an operation.
46
128
  #
47
129
  # operation 'foo', path: '/foo' do
48
130
  # parameter 'bar', type: 'string'
@@ -52,31 +134,35 @@ module Jsapi
52
134
  # end
53
135
  #
54
136
  # +name+ can be +nil+ if the controller handles one operation only.
137
+ #
138
+ # See Meta::Definitions#operations for further information.
55
139
  def operation(name = nil, **keywords, &block)
56
- _define('operation', name&.inspect) do
57
- operation_model = _meta_model.add_operation(name, keywords)
140
+ define('operation', name&.inspect) do
141
+ operation_model = @meta_model.add_operation(name, keywords)
58
142
  Operation.new(operation_model, &block) if block
59
143
  end
60
144
  end
61
145
 
62
- # Defines a reusable parameter.
146
+ # Specifies a reusable parameter.
63
147
  #
64
148
  # parameter 'foo', type: 'string'
65
149
  #
150
+ # See Meta::Definitions#parameters for further information.
66
151
  def parameter(name, **keywords, &block)
67
- _define('parameter', name.inspect) do
68
- parameter_model = _meta_model.add_parameter(name, keywords)
152
+ define('parameter', name.inspect) do
153
+ parameter_model = @meta_model.add_parameter(name, keywords)
69
154
  Parameter.new(parameter_model, &block) if block
70
155
  end
71
156
  end
72
157
 
73
- # Defines a reusable request body.
158
+ # Specifies a reusable request body.
74
159
  #
75
160
  # request_body 'foo', type: 'string'
76
161
  #
162
+ # See Meta::Definitions#request_bodies for further information.
77
163
  def request_body(name, **keywords, &block)
78
- _define('request_body', name.inspect) do
79
- request_body_model = _meta_model.add_request_body(name, keywords)
164
+ define('request_body', name.inspect) do
165
+ request_body_model = @meta_model.add_request_body(name, keywords)
80
166
  RequestBody.new(request_body_model, &block) if block
81
167
  end
82
168
  end
@@ -88,33 +174,87 @@ module Jsapi
88
174
  #
89
175
  def rescue_from(*klasses, with: nil)
90
176
  klasses.each do |klass|
91
- _meta_model.add_rescue_handler({ error_class: klass, status: with })
177
+ @meta_model.add_rescue_handler({ error_class: klass, status: with })
92
178
  end
93
179
  end
94
180
 
95
- # Defines a reusable response.
181
+ # Specifies a reusable response.
96
182
  #
97
183
  # response 'Foo', type: 'object' do
98
184
  # property 'bar', type: 'string'
99
185
  # end
186
+ #
187
+ # See Meta::Definitions#responses for further information.
100
188
  def response(name, **keywords, &block)
101
- _define('response', name.inspect) do
102
- response_model = _meta_model.add_response(name, keywords)
189
+ define('response', name.inspect) do
190
+ response_model = @meta_model.add_response(name, keywords)
103
191
  Response.new(response_model, &block) if block
104
192
  end
105
193
  end
106
194
 
107
- # Defines a reusable schema.
195
+ # Specifies a reusable schema.
108
196
  #
109
197
  # schema 'Foo' do
110
198
  # property 'bar', type: 'string'
111
199
  # end
200
+ #
201
+ # See Meta::Definitions#schemas for further information.
112
202
  def schema(name, **keywords, &block)
113
- _define('schema', name.inspect) do
114
- schema_model = _meta_model.add_schema(name, keywords)
203
+ define('schema', name.inspect) do
204
+ schema_model = @meta_model.add_schema(name, keywords)
115
205
  Schema.new(schema_model, &block) if block
116
206
  end
117
207
  end
208
+
209
+ ##
210
+ # :method: scheme
211
+ # :args: arg
212
+ # Specifies a URI scheme supported by the API.
213
+ #
214
+ # scheme 'https'
215
+ #
216
+ # See Meta::Definitions#schemes for further information.
217
+
218
+ ##
219
+ # :method: security_requirement
220
+ # :args: **keywords, &block
221
+ # Adds a security requirement.
222
+ #
223
+ # security_requirement do
224
+ # scheme 'basic_auth'
225
+ # end
226
+ #
227
+ # See Meta::Definitions#security_requirements for further information.
228
+
229
+ # Specifies a security scheme.
230
+ #
231
+ # security_scheme 'basic_auth', type: 'http', scheme: 'basic'
232
+ #
233
+ # See Meta::Definitions#security_schemes for further information.
234
+ def security_scheme(name, **keywords, &block)
235
+ define('security_scheme', name.inspect) do
236
+ security_scheme = @meta_model.add_security_scheme(name, keywords)
237
+ Base.new(security_scheme, &block) if block
238
+ end
239
+ end
240
+
241
+ ##
242
+ # :method: server
243
+ # :args: **keywords, &block
244
+ # Specifies a server providing the API.
245
+ #
246
+ # server url: 'https://foo.bar/foo'
247
+ #
248
+ # See Meta::Definitions#servers for further information.
249
+
250
+ ##
251
+ # :method: tag
252
+ # :args: **keywords, &block
253
+ # Specifies a tag.
254
+ #
255
+ # tag name: 'foo', description: 'description of foo'
256
+ #
257
+ # See Meta::Definitions#tags for further information.
118
258
  end
119
259
  end
120
260
  end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module DSL
5
+ module Examples
6
+ # Specifies an example.
7
+ #
8
+ # example 'foo', value: 'bar'
9
+ #
10
+ # example 'foo'
11
+ #
12
+ # The default name is <code>'default'</code>.
13
+ def example(name_or_value = nil, **keywords, &block)
14
+ define('example', name_or_value&.inspect) do
15
+ if keywords.any? || block
16
+ # example 'foo', value: 'bar', ...
17
+ name = name_or_value
18
+ else
19
+ # example 'foo'
20
+ name = nil
21
+ keywords = { value: name_or_value }
22
+ end
23
+
24
+ example = @meta_model.add_example(name, keywords)
25
+ Base.new(example, &block) if block
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -2,9 +2,34 @@
2
2
 
3
3
  module Jsapi
4
4
  module DSL
5
- # Used to specify details of an operation.
6
- class Operation < Node
7
- include OpenAPI::Callbacks
5
+ # Used to define an API operation.
6
+ class Operation < Base
7
+
8
+ # Specifies a callback.
9
+ #
10
+ # callback 'foo' do
11
+ # operation '{$request.query.bar}'
12
+ # end
13
+ #
14
+ # Refers a resuable callback if the `:ref` keyword is specified.
15
+ #
16
+ # callback ref: 'foo'
17
+ #
18
+ # Refers the reusable callback object with the same name if neither any
19
+ # keywords nor a block is specified.
20
+ #
21
+ # callback 'foo'
22
+ #
23
+ # See Meta::Operation#callbacks for further information.
24
+ def callback(name = nil, **keywords, &block)
25
+ define('callback', name&.inspect) do
26
+ name = keywords[:ref] if name.nil?
27
+ keywords = { ref: name } unless keywords.any? || block
28
+
29
+ callback_model = @meta_model.add_callback(name, keywords)
30
+ Callback.new(callback_model, &block) if block
31
+ end
32
+ end
8
33
 
9
34
  ##
10
35
  # :method: deprecated
@@ -24,7 +49,7 @@ module Jsapi
24
49
  #
25
50
  # See Meta::Operation#method for further information.
26
51
  def method(arg)
27
- _keyword(:method, arg)
52
+ keyword(:method, arg)
28
53
  end
29
54
 
30
55
  # Defines the model class to access top-level parameters by.
@@ -35,41 +60,41 @@ module Jsapi
35
60
  # end
36
61
  # end
37
62
  #
38
- # +klass+ can be any subclass of Model::Base. If block is given, an anonymous class
39
- # is created that inherits either from +klass+ or Model::Base.
63
+ # +klass+ can be any subclass of Model::Base. If block is given, an anonymous
64
+ # class is created that inherits either from +klass+ or Model::Base.
40
65
  def model(klass = nil, &block)
41
66
  if block
42
67
  klass = Class.new(klass || Model::Base)
43
68
  klass.class_eval(&block)
44
69
  end
45
- _meta_model.model = klass
70
+ @meta_model.model = klass
46
71
  end
47
72
 
48
- # Adds a parameter or a reference to a reusable parameter.
73
+ # Specifies a parameter
49
74
  #
50
- # # define a parameter
51
75
  # parameter 'foo', type: 'string'
52
76
  #
53
- # # define a nested parameter
54
77
  # parameter 'foo', type: 'object' do
55
78
  # property 'bar', type: 'string'
56
79
  # end
57
80
  #
58
- # # refer a reusable parameter
81
+ # Refers a resuable parameter if the `:ref` keyword is specified.
82
+ #
59
83
  # parameter ref: 'foo'
60
84
  #
61
- # Refers the reusable parameter with the same name if neither any keywords nor a
62
- # block is specified.
85
+ # Refers the reusable parameter with the same name if neither any keywords
86
+ # nor a block is specified.
63
87
  #
64
88
  # parameter 'foo'
65
89
  #
90
+ # See Meta::Operation#parameters for further information.
66
91
  def parameter(name = nil, **keywords, &block)
67
- _define('parameter', name&.inspect) do
92
+ define('parameter', name&.inspect) do
68
93
  name = keywords[:ref] if name.nil?
69
94
  keywords = { ref: name } unless keywords.any? || block
70
95
 
71
- parameter_model = _meta_model.add_parameter(name, keywords)
72
- _eval(parameter_model, Parameter, &block)
96
+ parameter_model = @meta_model.add_parameter(name, keywords)
97
+ Parameter.new(parameter_model, &block) if block
73
98
  end
74
99
  end
75
100
 
@@ -78,14 +103,14 @@ module Jsapi
78
103
  # :args: arg
79
104
  # Specifies the relative path of the operation.
80
105
 
81
- # Defines the request body or refers a reusable request body.
106
+ # Specifies the request body.
82
107
  #
83
- # # define a request body
84
108
  # request_body type: 'object' do
85
109
  # property 'foo', type: 'string'
86
110
  # end
87
111
  #
88
- # # refer a reusable request body
112
+ # Refers a resuable request body if the `:ref` keyword is specified.
113
+ #
89
114
  # request_body ref: 'foo'
90
115
  #
91
116
  # Refers the reusable request body with the same name if neither any
@@ -93,34 +118,37 @@ module Jsapi
93
118
  #
94
119
  # request_body 'foo'
95
120
  #
121
+ # See Meta::Operation#request_body for further information.
96
122
  def request_body(**keywords, &block)
97
- _define('request body') do
98
- _meta_model.request_body = keywords
99
- _eval(_meta_model.request_body, RequestBody, &block)
123
+ define('request body') do
124
+ @meta_model.request_body = keywords
125
+ RequestBody.new(@meta_model.request_body, &block) if block
100
126
  end
101
127
  end
102
128
 
103
- # Adds a response or a reference to a reusable response.
129
+ # Specifies a response.
104
130
  #
105
- # # define a response
106
131
  # response 200, type: 'object' do
107
132
  # property 'foo', type: 'string'
108
133
  # end
109
134
  #
110
- # # refer a reusable response
111
- # response 200, ref: 'foo'
112
- #
113
135
  # The default status is <code>"default"</code>.
114
136
  #
137
+ # Refers a resuable response if the `:ref` keyword is specified.
138
+ #
139
+ # response 200, ref: 'foo'
140
+ #
115
141
  # Refers the reusable response with the same name if neither any keywords
116
142
  # nor a block is specified.
117
143
  #
118
144
  # response 'foo'
119
145
  #
120
146
  # Raises an Error if name is specified together with keywords or a block.
147
+ #
148
+ # See Meta::Operation#responses for further information.
121
149
  def response(status_or_name = nil, name = nil, **keywords, &block)
122
- _define('response', status_or_name&.inspect) do
123
- raise Error, 'name cannot be specified together with keywords ' \
150
+ define('response', status_or_name&.inspect) do
151
+ raise Error, "name can't be specified together with keywords " \
124
152
  'or a block' if name && (keywords.any? || block)
125
153
 
126
154
  if keywords.any? || block
@@ -129,8 +157,8 @@ module Jsapi
129
157
  status = status_or_name if name
130
158
  keywords = { ref: name || status_or_name }
131
159
  end
132
- response_model = _meta_model.add_response(status, keywords)
133
- _eval(response_model, Response, &block)
160
+ response_model = @meta_model.add_response(status, keywords)
161
+ Response.new(response_model, &block) if block
134
162
  end
135
163
  end
136
164
 
@@ -149,7 +177,7 @@ module Jsapi
149
177
  ##
150
178
  # :method: tags
151
179
  # :args: names
152
- # Specifies all of the tags at once.
180
+ # Specifies all tags at once.
153
181
  #
154
182
  # tags %w[foo bar]
155
183
  end
@@ -2,9 +2,9 @@
2
2
 
3
3
  module Jsapi
4
4
  module DSL
5
- # Used to specify details of a parameter.
5
+ # Used to define a parameter.
6
6
  class Parameter < Schema
7
- include OpenAPI::Examples
7
+ include Examples
8
8
 
9
9
  ##
10
10
  # :method: deprecated
@@ -2,9 +2,9 @@
2
2
 
3
3
  module Jsapi
4
4
  module DSL
5
- # Used to specify details of a request body.
5
+ # Used to define a request body.
6
6
  class RequestBody < Schema
7
- include OpenAPI::Examples
7
+ include Examples
8
8
 
9
9
  ##
10
10
  # :method: deprecated
@@ -2,9 +2,9 @@
2
2
 
3
3
  module Jsapi
4
4
  module DSL
5
- # Used to specify details of a response.
5
+ # Used to define a response.
6
6
  class Response < Schema
7
- include OpenAPI::Examples
7
+ include Examples
8
8
 
9
9
  ##
10
10
  # :method: deprecated
@@ -18,33 +18,57 @@ module Jsapi
18
18
  # :args: arg
19
19
  # Specifies the description of the response.
20
20
 
21
- # Defines a link or refers a reusable link object.
21
+ # Specifies an HTTP header of the response.
22
+ #
23
+ # header 'X-Foo', type: 'string'
24
+ #
25
+ # Refers a resuable header if the `:ref` keyword is specified.
26
+ #
27
+ # header ref: 'x_foo'
28
+ #
29
+ # Refers the reusable header with the same name if neither any keywords
30
+ # nor a block is specified.
31
+ #
32
+ # header 'x_foo'
33
+ #
34
+ # See Meta::Response::Model#headers for further information.
35
+ def header(name = nil, **keywords, &block)
36
+ define('header', name&.inspect) do
37
+ name = keywords[:ref] if name.nil?
38
+ keywords = { ref: name } unless keywords.any? || block
39
+
40
+ header_model = @meta_model.add_header(name, keywords)
41
+ Base.new(header_model, &block) if block
42
+ end
43
+ end
44
+
45
+ # Specifies a link.
22
46
  #
23
- # # define a link
24
47
  # link 'foo', operation_id: 'bar'
25
48
  #
26
- # # refer a reusable link
49
+ # Refers a reusable link if the `:ref` keyword is specified.
50
+ #
27
51
  # link ref: 'foo'
28
52
  #
29
- # Refers the reusable link object with the same name if neither any
30
- # keywords nor a block is specified.
53
+ # Refers the reusable link with the same name if neither any keywords
54
+ # nor a block is specified.
31
55
  #
32
56
  # link 'foo'
33
57
  #
34
58
  def link(name = nil, **keywords, &block)
35
- _define('link', name&.inspect) do
59
+ define('link', name&.inspect) do
36
60
  name = keywords[:ref] if name.nil?
37
61
  keywords = { ref: name } unless keywords.any? || block
38
62
 
39
- link_model = _meta_model.add_link(name, keywords)
40
- Node.new(link_model, &block) if block
63
+ link_model = @meta_model.add_link(name, keywords)
64
+ Base.new(link_model, &block) if block
41
65
  end
42
66
  end
43
67
 
44
68
  ##
45
69
  # :method: locale
46
70
  # :args: arg
47
- # Specifies the locale to be used when rendering a response.
71
+ # Specifies the locale to be used when producing a response.
48
72
  #
49
73
  # locale :en
50
74
  end