Class: OpenapiFirst::Request
- Inherits:
-
Object
- Object
- OpenapiFirst::Request
- Defined in:
- lib/openapi_first/request.rb
Overview
Represents one request definition of an OpenAPI description. Note that this is not the same as an OpenAPI 3.x Operation. An 3.x Operation object can accept multiple requests, because it can handle multiple content-types. This class represents one of those requests.
Instance Attribute Summary collapse
-
#content_schema ⇒ Object
readonly
Returns the value of attribute content_schema.
-
#content_type ⇒ Object
readonly
Returns the value of attribute content_type.
-
#operation ⇒ Object
readonly
Returns the value of attribute operation.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#request_method ⇒ Object
readonly
Returns the value of attribute request_method.
Instance Method Summary collapse
-
#initialize(path:, request_method:, operation_object:, parameters:, content_type:, content_schema:, required_body:, hooks:, openapi_version:) ⇒ Request
constructor
A new instance of Request.
- #operation_id ⇒ Object
- #required_request_body? ⇒ Boolean
- #validate(request, route_params:) ⇒ Object
Constructor Details
#initialize(path:, request_method:, operation_object:, parameters:, content_type:, content_schema:, required_body:, hooks:, openapi_version:) ⇒ Request
Returns a new instance of Request.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/openapi_first/request.rb', line 13 def initialize(path:, request_method:, operation_object:, parameters:, content_type:, content_schema:, required_body:, hooks:, openapi_version:) @path = path @request_method = request_method @content_type = content_type @content_schema = content_schema @required_request_body = required_body == true @operation = operation_object @parameters = build_parameters(parameters) @request_parser = RequestParser.new( query_parameters: @parameters[:query], path_parameters: @parameters[:path], header_parameters: @parameters[:header], cookie_parameters: @parameters[:cookie], content_type: ) @validator = RequestValidator.new(self, hooks:, openapi_version:) end |
Instance Attribute Details
#content_schema ⇒ Object (readonly)
Returns the value of attribute content_schema.
33 34 35 |
# File 'lib/openapi_first/request.rb', line 33 def content_schema @content_schema end |
#content_type ⇒ Object (readonly)
Returns the value of attribute content_type.
33 34 35 |
# File 'lib/openapi_first/request.rb', line 33 def content_type @content_type end |
#operation ⇒ Object (readonly)
Returns the value of attribute operation.
33 34 35 |
# File 'lib/openapi_first/request.rb', line 33 def operation @operation end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
33 34 35 |
# File 'lib/openapi_first/request.rb', line 33 def path @path end |
#request_method ⇒ Object (readonly)
Returns the value of attribute request_method.
33 34 35 |
# File 'lib/openapi_first/request.rb', line 33 def request_method @request_method end |
Instance Method Details
#operation_id ⇒ Object
56 57 58 |
# File 'lib/openapi_first/request.rb', line 56 def operation_id @operation['operationId'] end |
#required_request_body? ⇒ Boolean
52 53 54 |
# File 'lib/openapi_first/request.rb', line 52 def required_request_body? @required_request_body end |
#validate(request, route_params:) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/openapi_first/request.rb', line 35 def validate(request, route_params:) parsed_values = {} error = catch FAILURE do parsed_values = @request_parser.parse(request, route_params:) @validator.call(parsed_values) nil end ValidatedRequest.new(request, parsed_values:, error:, request_definition: self) end |