Module: OpenapiFirst
- Defined in:
- lib/openapi_first.rb,
lib/openapi_first/config.rb,
lib/openapi_first/errors.rb,
lib/openapi_first/router.rb,
lib/openapi_first/plugins.rb,
lib/openapi_first/version.rb,
lib/openapi_first/operation.rb,
lib/openapi_first/definition.rb,
lib/openapi_first/use_router.rb,
lib/openapi_first/error_response.rb,
lib/openapi_first/operation_schemas.rb,
lib/openapi_first/schema_validation.rb,
lib/openapi_first/string_keyed_hash.rb,
lib/openapi_first/validation_result.rb,
lib/openapi_first/request_validation.rb,
lib/openapi_first/response_validator.rb,
lib/openapi_first/response_validation.rb,
lib/openapi_first/body_parser_middleware.rb,
lib/openapi_first/default_error_response.rb,
lib/openapi_first/request_body_validator.rb
Defined Under Namespace
Modules: Plugins, UseRouter Classes: BodyParserMiddleware, BodyParsingError, Config, DefaultErrorResponse, Definition, Error, ErrorResponse, NotFoundError, Operation, OperationSchemas, RequestBodyValidator, RequestInvalidError, RequestValidation, ResponseBodyInvalidError, ResponseCodeNotFoundError, ResponseContentTypeNotFoundError, ResponseHeaderInvalidError, ResponseInvalid, ResponseValidation, ResponseValidator, Router, SchemaValidation, StringKeyedHash, ValidationResult
Constant Summary collapse
- OPERATION =
The OpenAPI operation for the current request
'openapi.operation'- PARAMS =
Merged parsed path and query parameters
'openapi.params'- QUERY_PARAMS =
Parsed query parameters
'openapi.query'- PATH_PARAMS =
Parsed path parameters
'openapi.path_params'- HEADER_PARAMS =
Parsed header parameters, except for Content-Type, Accept and Authorization
'openapi.headers'- COOKIE_PARAMS =
Parsed cookie parameter values
'openapi.cookies'- REQUEST_BODY =
The parsed request body
'openapi.parsed_request_body'- VERSION =
'1.0.0.beta4'
Class Method Summary collapse
-
.error!(status, location = nil, title: nil, validation_result: nil) ⇒ Object
Throws an error in the middle of the request validation to stop validation and send a response.
- .load(spec_path, only: nil) ⇒ Object
Class Method Details
.error!(status, location = nil, title: nil, validation_result: nil) ⇒ Object
Throws an error in the middle of the request validation to stop validation and send a response.
40 41 42 43 44 45 46 47 |
# File 'lib/openapi_first.rb', line 40 def error!(status, location = nil, title: nil, validation_result: nil) throw :error, { status:, location:, title: title || validation_result&.output&.fetch('error') || Rack::Utils::HTTP_STATUS_CODES[status], validation_result: } end |
.load(spec_path, only: nil) ⇒ Object
50 51 52 53 54 55 56 57 |
# File 'lib/openapi_first.rb', line 50 def self.load(spec_path, only: nil) resolved = Dir.chdir(File.dirname(spec_path)) do content = YAML.load_file(File.basename(spec_path)) JsonRefs.call(content, resolve_local_ref: true, resolve_file_ref: true) end resolved['paths'].filter!(&->(key, _) { only.call(key) }) if only Definition.new(resolved, spec_path) end |