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
rubocop:enable Metrics/MethodLength.
-
#content_type ⇒ Object
readonly
rubocop:enable Metrics/MethodLength.
-
#key ⇒ Object
readonly
rubocop:enable Metrics/MethodLength.
-
#operation ⇒ Object
readonly
rubocop:enable Metrics/MethodLength.
-
#path ⇒ Object
readonly
rubocop:enable Metrics/MethodLength.
-
#request_method ⇒ Object
readonly
rubocop:enable Metrics/MethodLength.
Instance Method Summary collapse
- #allow_empty_content? ⇒ Boolean
-
#initialize(path:, request_method:, operation_object:, parameters:, content_type:, content_schema:, required_body:, key:) ⇒ Request
constructor
rubocop:disable Metrics/MethodLength.
- #operation_id ⇒ Object
- #validate(request, route_params:) ⇒ Object
Constructor Details
#initialize(path:, request_method:, operation_object:, parameters:, content_type:, content_schema:, required_body:, key:) ⇒ Request
rubocop:disable Metrics/MethodLength
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/openapi_first/request.rb', line 14 def initialize(path:, request_method:, operation_object:, parameters:, content_type:, content_schema:, required_body:, key:) @path = path @request_method = request_method @content_type = content_type @content_schema = content_schema @operation = operation_object @allow_empty_content = content_type.nil? || required_body == false @key = key @request_parser = RequestParser.new( query_parameters: parameters.query, path_parameters: parameters.path, header_parameters: parameters.header, cookie_parameters: parameters., content_type: ) @validator = RequestValidator.new( content_schema:, required_request_body: required_body == true, path_schema: parameters.path_schema, query_schema: parameters.query_schema, header_schema: parameters.header_schema, cookie_schema: parameters. ) end |
Instance Attribute Details
#content_schema ⇒ Object (readonly)
rubocop:enable Metrics/MethodLength
41 42 43 |
# File 'lib/openapi_first/request.rb', line 41 def content_schema @content_schema end |
#content_type ⇒ Object (readonly)
rubocop:enable Metrics/MethodLength
41 42 43 |
# File 'lib/openapi_first/request.rb', line 41 def content_type @content_type end |
#key ⇒ Object (readonly)
rubocop:enable Metrics/MethodLength
41 42 43 |
# File 'lib/openapi_first/request.rb', line 41 def key @key end |
#operation ⇒ Object (readonly)
rubocop:enable Metrics/MethodLength
41 42 43 |
# File 'lib/openapi_first/request.rb', line 41 def operation @operation end |
#path ⇒ Object (readonly)
rubocop:enable Metrics/MethodLength
41 42 43 |
# File 'lib/openapi_first/request.rb', line 41 def path @path end |
#request_method ⇒ Object (readonly)
rubocop:enable Metrics/MethodLength
41 42 43 |
# File 'lib/openapi_first/request.rb', line 41 def request_method @request_method end |
Instance Method Details
#allow_empty_content? ⇒ Boolean
43 44 45 |
# File 'lib/openapi_first/request.rb', line 43 def allow_empty_content? @allow_empty_content end |
#operation_id ⇒ Object
57 58 59 |
# File 'lib/openapi_first/request.rb', line 57 def operation_id @operation['operationId'] end |
#validate(request, route_params:) ⇒ Object
47 48 49 50 51 52 53 54 55 |
# File 'lib/openapi_first/request.rb', line 47 def validate(request, route_params:) parsed_request = nil error = catch FAILURE do parsed_request = @request_parser.parse(request, route_params:) @validator.call(parsed_request) nil end ValidatedRequest.new(request, parsed_request:, error:, request_definition: self) end |