Module: Jsapi::DSL::ClassMethods
- Defined in:
- lib/jsapi/dsl/class_methods.rb
Instance Method Summary collapse
-
#api_definitions(&block) ⇒ Object
The API definitions of the current class.
-
#api_include(*klasses) ⇒ Object
Includes API definitions from
klasses. -
#api_operation(name = nil, **options, &block) ⇒ Object
Defines an operation.
-
#api_parameter(name, **options, &block) ⇒ Object
Defines a reusable parameter.
-
#api_request_body(name, **options, &block) ⇒ Object
Defines a reusable request body.
-
#api_rescue_from(*klasses, with: nil) ⇒ Object
Specifies the HTTP status code of an error response rendered when an exception of any of
klasseshas been raised. -
#api_response(name, **options, &block) ⇒ Object
Defines a reusable response.
-
#api_schema(name, **options, &block) ⇒ Object
Defines a reusable schema.
-
#openapi(**keywords, &block) ⇒ Object
Defines the root of an OpenAPI document.
Instance Method Details
#api_definitions(&block) ⇒ Object
The API definitions of the current class.
7 8 9 10 11 |
# File 'lib/jsapi/dsl/class_methods.rb', line 7 def api_definitions(&block) @api_definitions ||= Meta::Definitions.new(self) Definitions.new(@api_definitions, &block) if block @api_definitions end |
#api_include(*klasses) ⇒ Object
Includes API definitions from klasses.
14 15 16 |
# File 'lib/jsapi/dsl/class_methods.rb', line 14 def api_include(*klasses) api_definitions { include(*klasses) } end |
#api_operation(name = nil, **options, &block) ⇒ Object
Defines an operation.
api_operation 'foo', path: '/foo' do
parameter 'bar', type: 'string'
response do
property 'foo', type: 'string'
end
end
name can be nil if the controller handles one operation only.
28 29 30 |
# File 'lib/jsapi/dsl/class_methods.rb', line 28 def api_operation(name = nil, **, &block) api_definitions { operation(name, **, &block) } end |
#api_parameter(name, **options, &block) ⇒ Object
Defines a reusable parameter.
api_parameter 'foo', type: 'string'
36 37 38 |
# File 'lib/jsapi/dsl/class_methods.rb', line 36 def api_parameter(name, **, &block) api_definitions { parameter(name, **, &block) } end |
#api_request_body(name, **options, &block) ⇒ Object
Defines a reusable request body.
api_request_body 'foo', type: 'string'
44 45 46 |
# File 'lib/jsapi/dsl/class_methods.rb', line 44 def api_request_body(name, **, &block) api_definitions { request_body(name, **, &block) } end |
#api_rescue_from(*klasses, with: nil) ⇒ Object
Specifies the HTTP status code of an error response rendered when an exception of any of klasses has been raised.
api_rescue_from Jsapi::Controller::ParametersInvalid, with: 400
53 54 55 |
# File 'lib/jsapi/dsl/class_methods.rb', line 53 def api_rescue_from(*klasses, with: nil) api_definitions { rescue_from(*klasses, with: with) } end |
#api_response(name, **options, &block) ⇒ Object
Defines a reusable response.
api_response 'Foo', type: 'object' do
property 'bar', type: 'string'
end
62 63 64 |
# File 'lib/jsapi/dsl/class_methods.rb', line 62 def api_response(name, **, &block) api_definitions { response(name, **, &block) } end |
#api_schema(name, **options, &block) ⇒ Object
Defines a reusable schema.
api_schema 'Foo' do
property 'bar', type: 'string'
end
71 72 73 |
# File 'lib/jsapi/dsl/class_methods.rb', line 71 def api_schema(name, **, &block) api_definitions { schema(name, **, &block) } end |
#openapi(**keywords, &block) ⇒ Object
Defines the root of an OpenAPI document.
openapi do
info title: 'Foo', version: '1'
end
80 81 82 |
# File 'lib/jsapi/dsl/class_methods.rb', line 80 def openapi(**keywords, &block) api_definitions { openapi(**keywords, &block) } end |