jsapi 0.8.0 → 0.9.1

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 (107) hide show
  1. checksums.yaml +4 -4
  2. data/lib/jsapi/configuration.rb +28 -0
  3. data/lib/jsapi/controller/methods.rb +1 -1
  4. data/lib/jsapi/dsl/base.rb +92 -0
  5. data/lib/jsapi/dsl/callback.rb +21 -0
  6. data/lib/jsapi/dsl/class_methods.rb +143 -16
  7. data/lib/jsapi/dsl/definitions.rb +173 -33
  8. data/lib/jsapi/dsl/examples.rb +30 -0
  9. data/lib/jsapi/dsl/operation.rb +60 -32
  10. data/lib/jsapi/dsl/parameter.rb +2 -2
  11. data/lib/jsapi/dsl/request_body.rb +2 -2
  12. data/lib/jsapi/dsl/response.rb +35 -11
  13. data/lib/jsapi/dsl/schema.rb +16 -16
  14. data/lib/jsapi/dsl.rb +4 -4
  15. data/lib/jsapi/meta/base/attributes.rb +21 -19
  16. data/lib/jsapi/meta/base/model.rb +15 -7
  17. data/lib/jsapi/meta/callback/model.rb +34 -0
  18. data/lib/jsapi/meta/callback/reference.rb +14 -0
  19. data/lib/jsapi/meta/callback.rb +19 -0
  20. data/lib/jsapi/meta/contact.rb +30 -0
  21. data/lib/jsapi/meta/defaults.rb +2 -2
  22. data/lib/jsapi/meta/definitions.rb +230 -124
  23. data/lib/jsapi/meta/example/model.rb +43 -0
  24. data/lib/jsapi/meta/example/reference.rb +14 -0
  25. data/lib/jsapi/meta/example.rb +19 -0
  26. data/lib/jsapi/meta/external_documentation.rb +25 -0
  27. data/lib/jsapi/meta/header/model.rb +81 -0
  28. data/lib/jsapi/meta/header/reference.rb +14 -0
  29. data/lib/jsapi/meta/header.rb +19 -0
  30. data/lib/jsapi/meta/info.rb +52 -0
  31. data/lib/jsapi/meta/license.rb +25 -0
  32. data/lib/jsapi/meta/link/model.rb +48 -0
  33. data/lib/jsapi/meta/link/reference.rb +14 -0
  34. data/lib/jsapi/meta/link.rb +19 -0
  35. data/lib/jsapi/meta/oauth_flow.rb +52 -0
  36. data/lib/jsapi/meta/openapi.rb +0 -28
  37. data/lib/jsapi/meta/operation.rb +19 -18
  38. data/lib/jsapi/meta/parameter/model.rb +6 -4
  39. data/lib/jsapi/meta/parameter/reference.rb +6 -4
  40. data/lib/jsapi/meta/parameter/to_openapi.rb +13 -0
  41. data/lib/jsapi/meta/parameter.rb +2 -1
  42. data/lib/jsapi/meta/property.rb +1 -1
  43. data/lib/jsapi/meta/request_body/model.rb +6 -5
  44. data/lib/jsapi/meta/request_body.rb +1 -1
  45. data/lib/jsapi/meta/response/model.rb +16 -13
  46. data/lib/jsapi/meta/response.rb +1 -1
  47. data/lib/jsapi/meta/schema/array.rb +1 -1
  48. data/lib/jsapi/meta/schema/base.rb +5 -5
  49. data/lib/jsapi/meta/schema/discriminator.rb +2 -2
  50. data/lib/jsapi/meta/schema/object.rb +3 -3
  51. data/lib/jsapi/meta/schema/reference.rb +1 -1
  52. data/lib/jsapi/meta/schema.rb +2 -2
  53. data/lib/jsapi/meta/security_requirement.rb +25 -0
  54. data/lib/jsapi/meta/security_scheme/api_key.rb +38 -0
  55. data/lib/jsapi/meta/security_scheme/base.rb +14 -0
  56. data/lib/jsapi/meta/security_scheme/http/basic.rb +34 -0
  57. data/lib/jsapi/meta/security_scheme/http/bearer.rb +36 -0
  58. data/lib/jsapi/meta/security_scheme/http/other.rb +36 -0
  59. data/lib/jsapi/meta/security_scheme/http.rb +29 -0
  60. data/lib/jsapi/meta/security_scheme/oauth2.rb +44 -0
  61. data/lib/jsapi/meta/security_scheme/open_id_connect.rb +32 -0
  62. data/lib/jsapi/meta/security_scheme.rb +49 -0
  63. data/lib/jsapi/meta/server.rb +34 -0
  64. data/lib/jsapi/meta/server_variable.rb +34 -0
  65. data/lib/jsapi/meta/tag.rb +34 -0
  66. data/lib/jsapi/meta.rb +15 -1
  67. data/lib/jsapi/model/base.rb +5 -5
  68. data/lib/jsapi/version.rb +1 -1
  69. data/lib/jsapi.rb +1 -1
  70. metadata +39 -42
  71. data/lib/jsapi/dsl/node.rb +0 -62
  72. data/lib/jsapi/dsl/openapi/callback.rb +0 -23
  73. data/lib/jsapi/dsl/openapi/callbacks.rb +0 -34
  74. data/lib/jsapi/dsl/openapi/examples.rb +0 -32
  75. data/lib/jsapi/dsl/openapi/root.rb +0 -126
  76. data/lib/jsapi/dsl/openapi.rb +0 -6
  77. data/lib/jsapi/meta/openapi/callback/model.rb +0 -34
  78. data/lib/jsapi/meta/openapi/callback/reference.rb +0 -16
  79. data/lib/jsapi/meta/openapi/callback.rb +0 -21
  80. data/lib/jsapi/meta/openapi/contact.rb +0 -32
  81. data/lib/jsapi/meta/openapi/example/model.rb +0 -44
  82. data/lib/jsapi/meta/openapi/example/reference.rb +0 -16
  83. data/lib/jsapi/meta/openapi/example.rb +0 -21
  84. data/lib/jsapi/meta/openapi/external_documentation.rb +0 -27
  85. data/lib/jsapi/meta/openapi/header/model.rb +0 -82
  86. data/lib/jsapi/meta/openapi/header/reference.rb +0 -16
  87. data/lib/jsapi/meta/openapi/header.rb +0 -21
  88. data/lib/jsapi/meta/openapi/info.rb +0 -54
  89. data/lib/jsapi/meta/openapi/license.rb +0 -27
  90. data/lib/jsapi/meta/openapi/link/model.rb +0 -50
  91. data/lib/jsapi/meta/openapi/link/reference.rb +0 -16
  92. data/lib/jsapi/meta/openapi/link.rb +0 -21
  93. data/lib/jsapi/meta/openapi/oauth_flow.rb +0 -52
  94. data/lib/jsapi/meta/openapi/root.rb +0 -132
  95. data/lib/jsapi/meta/openapi/security_requirement.rb +0 -27
  96. data/lib/jsapi/meta/openapi/security_scheme/api_key.rb +0 -40
  97. data/lib/jsapi/meta/openapi/security_scheme/base.rb +0 -16
  98. data/lib/jsapi/meta/openapi/security_scheme/http/basic.rb +0 -36
  99. data/lib/jsapi/meta/openapi/security_scheme/http/bearer.rb +0 -39
  100. data/lib/jsapi/meta/openapi/security_scheme/http/other.rb +0 -39
  101. data/lib/jsapi/meta/openapi/security_scheme/http.rb +0 -31
  102. data/lib/jsapi/meta/openapi/security_scheme/oauth2.rb +0 -46
  103. data/lib/jsapi/meta/openapi/security_scheme/open_id_connect.rb +0 -34
  104. data/lib/jsapi/meta/openapi/security_scheme.rb +0 -51
  105. data/lib/jsapi/meta/openapi/server.rb +0 -36
  106. data/lib/jsapi/meta/openapi/server_variable.rb +0 -36
  107. data/lib/jsapi/meta/openapi/tag.rb +0 -36
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 41bcc8f72dc668c6df55dfc73e6e2c9cc6fde569ebe008e503586100e0b3bba1
4
- data.tar.gz: 9667a2661824e0d3a47675e835f3372cfd22bff71ab8c7bb3bde3c0e56cc78be
3
+ metadata.gz: 4631e17cbd92a36a62ab6e7aa139b65afa83fccc2c41da34c3f757f2b077340f
4
+ data.tar.gz: 4c547aeb52a0fc74c09389f2c97dd0b8c90883fd36c79b9c502689a25379f3f5
5
5
  SHA512:
6
- metadata.gz: 576422bac22ee56e77ab160e50033a78ba1f02039fd5a7686583d0778f049e331892bb5d7692dcdc428c9b250706f13bf6e585db4472d40e31d63537116d9f37
7
- data.tar.gz: e3ef8964a2a55d6f245a8982e7dcad76f564d066af119eec43edb1b5bc579f1771ce87e747924e5cd2d6b650e07e44515ff7e722860a4c4ee8c6fa7e8b0360cb
6
+ metadata.gz: 1db64f601b34597e5b13ee820482c5a72d2adef153feac7ef3e1141804df36cc8816f665ee18c73e1b30e50a8c13454bed4c7562d447b2fdaf1b3814d863bd09
7
+ data.tar.gz: a4bd27f4fcc7c50ee9447e70777ca54de3e81ee6fd7ab3124817baf54511c90d0d95cf461c09c7fdc42a3bf8b57bb62d91954bc96d8a44a77eb15f9d53d2f5be
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ # Holds the \Jsapi configuration.
5
+ class Configuration
6
+ # The path where the API definitions are located relative to +Rails.root+.
7
+ # The default is <code>"app/api_defs"</code>.
8
+ attr_accessor :api_defs_path
9
+
10
+ def initialize # :nodoc:
11
+ @api_defs_path = 'app/api_defs'
12
+ end
13
+
14
+ # Returns the absolute +Pathname+ for +args+ within +api_defs_path+.
15
+ def pathname(*args)
16
+ return unless (root = Rails.root)
17
+
18
+ root.join(*[api_defs_path, args].flatten)
19
+ end
20
+ end
21
+
22
+ class << self
23
+ # The singleton \Jsapi configuration.
24
+ def configuration
25
+ @configuration ||= Configuration.new
26
+ end
27
+ end
28
+ end
@@ -162,7 +162,7 @@ module Jsapi
162
162
  (operation.model || Model::Base).new(
163
163
  Parameters.new(
164
164
  params.except(:action, :controller, :format).permit!,
165
- headers,
165
+ request.headers,
166
166
  operation,
167
167
  definitions,
168
168
  strong: strong
@@ -0,0 +1,92 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module DSL
5
+ class Base
6
+ def initialize(meta_model, pathname = nil, parent: nil, &block)
7
+ @meta_model = meta_model
8
+ @pathname = pathname
9
+ @parent = parent
10
+
11
+ # Raise an error when pathname is attempted to be imported again
12
+ if pathname && (ancestor = parent)
13
+ while ancestor
14
+ if ancestor.pathname == pathname
15
+ raise Error, "Attempted #{pathname.to_path.inspect} to be imported again"
16
+ end
17
+
18
+ ancestor = ancestor.parent
19
+ end
20
+ end
21
+
22
+ # Evaluate the file to be imported
23
+ instance_eval(pathname.read, pathname.to_path) if pathname
24
+
25
+ # Evaluate block
26
+ if block
27
+ if meta_model.reference?
28
+ raise Error, "reference can't be specified together with a block"
29
+ end
30
+
31
+ instance_eval(&block)
32
+ end
33
+ end
34
+
35
+ # Imports the file named +filename+ relative to +Jsapi.configation.path+.
36
+ def import(filename)
37
+ raise ArgumentError, "file name can't be blank" if filename.blank?
38
+
39
+ pathname = Jsapi.configuration.pathname("#{filename}.rb")
40
+ self.class.new(@meta_model, pathname, parent: self)
41
+ end
42
+
43
+ # Imports the file named +filename+ relative to the current file's path.
44
+ def import_relative(filename)
45
+ raise ArgumentError, "file name can't be blank" if filename.blank?
46
+
47
+ pathname = (@pathname&.parent || Jsapi.configuration.pathname) + "#{filename}.rb"
48
+ self.class.new(@meta_model, pathname, parent: self)
49
+ end
50
+
51
+ def respond_to_missing?(*args) # :nodoc:
52
+ keyword?(args.first)
53
+ end
54
+
55
+ protected
56
+
57
+ attr_reader :parent, :pathname
58
+
59
+ private
60
+
61
+ def define(*args, &block)
62
+ block.call
63
+ rescue Error => e
64
+ raise e.prepend_origin(args.compact.join(' '))
65
+ rescue StandardError => e
66
+ raise Error.new(e, args.compact.join(' ').presence)
67
+ end
68
+
69
+ def find_method(name)
70
+ ["#{name}=", "add_#{name}"].find do |method|
71
+ @meta_model.respond_to?(method)
72
+ end
73
+ end
74
+
75
+ def keyword(name, *params, &block)
76
+ method = find_method(name)
77
+ raise "unsupported keyword: #{name}" unless method
78
+
79
+ define(name) do
80
+ result = @meta_model.public_send(method, *params)
81
+ Base.new(result, &block) if block
82
+ end
83
+ end
84
+
85
+ def keyword?(name)
86
+ find_method(name).present?
87
+ end
88
+
89
+ alias method_missing keyword
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Jsapi
4
+ module DSL
5
+ # Used to specify an OpenAPI callback object.
6
+ class Callback < Base
7
+
8
+ # Adds a callback operation.
9
+ #
10
+ # operation '{$request.query.foo}' do
11
+ # parameter 'bar', type: 'string'
12
+ # end
13
+ def operation(expression, **keywords, &block)
14
+ define('operation', expression.inspect) do
15
+ operation_model = @meta_model.add_operation(expression, keywords)
16
+ Operation.new(operation_model, &block) if block
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -3,35 +3,129 @@
3
3
  module Jsapi
4
4
  module DSL
5
5
  module ClassMethods
6
+ # Specifies the base path of the API.
7
+ #
8
+ # api_base_path '/foo'
9
+ #
10
+ def api_base_path(arg)
11
+ api_definitions { base_path(arg) }
12
+ end
13
+
14
+ # Specifies a reusable callback.
15
+ #
16
+ # api_callback 'onFoo' do
17
+ # operation '{$request.query.foo}', path: '/bar'
18
+ # end
19
+ #
20
+ def api_callback(name, **keywords, &block)
21
+ api_definitions { callback(name, **keywords, &block) }
22
+ end
23
+
6
24
  # Specifies the general default values for +type+.
7
25
  #
8
- # api_default 'array', read: [], write: []
26
+ # api_default 'array', within_requests: [], within_responses: []
9
27
  #
10
28
  def api_default(type, **keywords, &block)
11
29
  api_definitions { default(type, **keywords, &block) }
12
30
  end
13
31
 
14
- # The API definitions of the current class.
15
- def api_definitions(&block)
16
- @api_definitions ||= Meta::Definitions.new(
17
- owner: self,
18
- parent: superclass.try(:api_definitions)
19
- )
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?
20
53
  Definitions.new(@api_definitions, &block) if block
54
+
21
55
  @api_definitions
22
56
  end
23
57
 
58
+ # Specifies a reusable example.
59
+ #
60
+ # example 'foo', value: 'bar'
61
+ #
62
+ def api_example(name, **keywords, &block)
63
+ api_definitions { example(name, **keywords, &block) }
64
+ end
65
+
66
+ # Specifies the external documentation.
67
+ #
68
+ # api_external_docs url: 'https://foo.bar'
69
+ #
70
+ def api_external_docs(**keywords, &block)
71
+ api_definitions { external_docs(**keywords, &block) }
72
+ end
73
+
74
+ # Specifies a reusable header.
75
+ #
76
+ # api_header 'foo', type: 'string'
77
+ #
78
+ def api_header(name, **keywords, &block)
79
+ api_definitions { header(name, **keywords, &block) }
80
+ end
81
+
82
+ # Specifies the host serving the API.
83
+ #
84
+ # api_host 'foo.bar'
85
+ #
86
+ def api_host(arg)
87
+ api_definitions { host(arg) }
88
+ end
89
+
90
+ # Imports the file named +filename+ relative to +Jsapi.configation.path+.
91
+ def api_import(filename)
92
+ api_definitions { import(filename) }
93
+ end
94
+
24
95
  # Includes API definitions from +klasses+.
25
96
  def api_include(*klasses)
26
97
  api_definitions { include(*klasses) }
27
98
  end
28
99
 
100
+ # Specifies general information about the API.
101
+ #
102
+ # api_info title: 'Foo', version: '1' do
103
+ # contact name: 'bar'
104
+ # end
105
+ def api_info(**keywords, &block)
106
+ api_definitions { info(**keywords, &block) }
107
+ end
108
+
109
+ # Specifies a reusable link.
110
+ #
111
+ # api_link 'foo', operation_id: 'bar'
112
+ #
113
+ def api_link(name, **keywords, &block)
114
+ api_definitions { link(name, **keywords, &block) }
115
+ end
116
+
29
117
  # Registers a callback to be called when rescuing an exception.
118
+ #
119
+ # api_on_rescue :foo
120
+ #
121
+ # api_on_rescue do |error|
122
+ # # ...
123
+ # end
30
124
  def api_on_rescue(method = nil, &block)
31
125
  api_definitions { on_rescue(method, &block) }
32
126
  end
33
127
 
34
- # Defines an operation.
128
+ # Specifies an operation.
35
129
  #
36
130
  # api_operation 'foo', path: '/foo' do
37
131
  # parameter 'bar', type: 'string'
@@ -45,7 +139,7 @@ module Jsapi
45
139
  api_definitions { operation(name, **keywords, &block) }
46
140
  end
47
141
 
48
- # Defines a reusable parameter.
142
+ # Specifies a reusable parameter.
49
143
  #
50
144
  # api_parameter 'foo', type: 'string'
51
145
  #
@@ -70,7 +164,7 @@ module Jsapi
70
164
  api_definitions { rescue_from(*klasses, with: with) }
71
165
  end
72
166
 
73
- # Defines a reusable response.
167
+ # Specifies a reusable response.
74
168
  #
75
169
  # api_response 'Foo', type: 'object' do
76
170
  # property 'bar', type: 'string'
@@ -79,7 +173,7 @@ module Jsapi
79
173
  api_definitions { response(name, **keywords, &block) }
80
174
  end
81
175
 
82
- # Defines a reusable schema.
176
+ # Specifies a reusable schema.
83
177
  #
84
178
  # api_schema 'Foo' do
85
179
  # property 'bar', type: 'string'
@@ -88,13 +182,46 @@ module Jsapi
88
182
  api_definitions { schema(name, **keywords, &block) }
89
183
  end
90
184
 
91
- # Defines the root of an OpenAPI document.
185
+ # Specifies a URI scheme supported by the API.
92
186
  #
93
- # openapi do
94
- # info title: 'Foo', version: '1'
187
+ # api_scheme 'https'
188
+ #
189
+ def api_scheme(arg)
190
+ api_definitions { scheme(arg) }
191
+ end
192
+
193
+ # Specifies a security requirement.
194
+ #
195
+ # api_security_requirement do
196
+ # scheme 'basic_auth'
95
197
  # end
96
- def openapi(**keywords, &block)
97
- api_definitions { openapi(**keywords, &block) }
198
+ #
199
+ def api_security_requirement(**keywords, &block)
200
+ api_definitions { security_requirement(**keywords, &block) }
201
+ end
202
+
203
+ # Specifies a security scheme.
204
+ #
205
+ # api_security_scheme 'basic_auth', type: 'http', scheme: 'basic'
206
+ #
207
+ def api_security_scheme(name, **keywords, &block)
208
+ api_definitions { security_scheme(name, **keywords, &block) }
209
+ end
210
+
211
+ # Specifies a server providing the API.
212
+ #
213
+ # api_server url: 'https://foo.bar/foo'
214
+ #
215
+ def api_server(**keywords, &block)
216
+ api_definitions { server(**keywords, &block) }
217
+ end
218
+
219
+ # Specifies a tag.
220
+ #
221
+ # api_tag name: 'foo', description: 'description of foo'
222
+ #
223
+ def api_tag(**keywords, &block)
224
+ api_definitions { tag(**keywords, &block) }
98
225
  end
99
226
  end
100
227
  end
@@ -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