Class: OpenapiFirst::ValidatedRequest
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- OpenapiFirst::ValidatedRequest
- Extended by:
- Forwardable
- Defined in:
- lib/openapi_first/validated_request.rb
Overview
A validated request. It can be valid or not.
Instance Attribute Summary collapse
-
#error ⇒ Failure?
readonly
The error that occurred during validation.
-
#parsed_values ⇒ Object
readonly
Returns the value of attribute parsed_values.
-
#request_definition ⇒ Object
readonly
Returns the value of attribute request_definition.
Instance Method Summary collapse
-
#initialize(original_request, error:, parsed_values: {}, request_definition: nil) ⇒ ValidatedRequest
constructor
A new instance of ValidatedRequest.
-
#invalid? ⇒ Boolean
Checks if the request is invalid.
-
#known? ⇒ Boolean
Returns true if the request is defined.
-
#operation ⇒ Hash
The OpenAPI 3 operation object.
-
#operation_id ⇒ String?
The OpenAPI 3 operationId.
-
#parsed_body ⇒ Object
Parsed body.
-
#parsed_cookies ⇒ Object
Parsed cookies.
-
#parsed_headers ⇒ Object
Parsed headers.
-
#parsed_params ⇒ Object
Merged path, query, body parameters.
-
#parsed_path_parameters ⇒ Object
Parsed path parameters @return [Hash] A string keyed hash of path parameters.
-
#parsed_query ⇒ Object
Parsed query parameters.
-
#valid? ⇒ Boolean
Checks if the request is valid.
Constructor Details
#initialize(original_request, error:, parsed_values: {}, request_definition: nil) ⇒ ValidatedRequest
Returns a new instance of ValidatedRequest.
11 12 13 14 15 16 |
# File 'lib/openapi_first/validated_request.rb', line 11 def initialize(original_request, error:, parsed_values: {}, request_definition: nil) super(original_request) @parsed_values = Hash.new({}).merge(parsed_values) @error = error @request_definition = request_definition end |
Instance Attribute Details
#error ⇒ Failure? (readonly)
Returns The error that occurred during validation.
22 |
# File 'lib/openapi_first/validated_request.rb', line 22 attr_reader :parsed_values, :error, :request_definition |
#parsed_values ⇒ Object (readonly)
Returns the value of attribute parsed_values.
22 23 24 |
# File 'lib/openapi_first/validated_request.rb', line 22 def parsed_values @parsed_values end |
#request_definition ⇒ Object (readonly)
Returns the value of attribute request_definition.
22 |
# File 'lib/openapi_first/validated_request.rb', line 22 attr_reader :parsed_values, :error, :request_definition |
Instance Method Details
#invalid? ⇒ Boolean
Checks if the request is invalid.
66 67 68 |
# File 'lib/openapi_first/validated_request.rb', line 66 def invalid? !valid? end |
#known? ⇒ Boolean
Returns true if the request is defined.
71 72 73 |
# File 'lib/openapi_first/validated_request.rb', line 71 def known? request_definition != nil end |
#operation ⇒ Hash
Returns The OpenAPI 3 operation object.
29 |
# File 'lib/openapi_first/validated_request.rb', line 29 def_delegators :request_definition, :operation_id, :operation |
#operation_id ⇒ String?
Returns The OpenAPI 3 operationId.
29 |
# File 'lib/openapi_first/validated_request.rb', line 29 def_delegators :request_definition, :operation_id, :operation |
#parsed_body ⇒ Object
Parsed body. This parses the body according to the content type. Note that this returns the hole body, not only the fields that are defined in the OpenAPI spec. You can use JSON Schemas ‘additionalProperties` or `unevaluatedProperties` to returns a validation error if the body contains unknown fields.
56 57 58 |
# File 'lib/openapi_first/validated_request.rb', line 56 def parsed_body parsed_values[:body] end |
#parsed_cookies ⇒ Object
Parsed cookies. This only returns the query parameters that are defined in the OpenAPI spec.
48 49 50 |
# File 'lib/openapi_first/validated_request.rb', line 48 def parsed_values[:cookies] end |
#parsed_headers ⇒ Object
Parsed headers. This only returns the query parameters that are defined in the OpenAPI spec.
43 44 45 |
# File 'lib/openapi_first/validated_request.rb', line 43 def parsed_headers parsed_values[:headers] end |
#parsed_params ⇒ Object
Merged path, query, body parameters. Here path has the highest precedence, then query, then body.
77 78 79 |
# File 'lib/openapi_first/validated_request.rb', line 77 def parsed_params @parsed_params ||= parsed_body.merge(parsed_query, parsed_path_parameters) end |
#parsed_path_parameters ⇒ Object
Parsed path parameters
@return [Hash] A string keyed hash of path parameters
33 34 35 |
# File 'lib/openapi_first/validated_request.rb', line 33 def parsed_path_parameters parsed_values[:path] end |
#parsed_query ⇒ Object
Parsed query parameters. This only returns the query parameters that are defined in the OpenAPI spec.
38 39 40 |
# File 'lib/openapi_first/validated_request.rb', line 38 def parsed_query parsed_values[:query] end |
#valid? ⇒ Boolean
Checks if the request is valid.
61 62 63 |
# File 'lib/openapi_first/validated_request.rb', line 61 def valid? error.nil? end |