Download the PHP package hkarlstrom/openapi-validation-middleware without Composer

On this page you can find all versions of the php package hkarlstrom/openapi-validation-middleware. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package openapi-validation-middleware

OpenAPI Validation Middleware

PSR-7 and PSR-15 OpenAPI Validation Middleware

The middleware parses an OpenAPI definition document (openapi.json or openapi.yaml) and validates:

The middleware can be used with any framework using PSR-7 and PSR-15 style middlewares.

All testing has been done using Slim Framework. The tests are done with a openapi.json file that is valid according to Swagger/OpenAPI CLI

Installation

It's recommended that you use Composer to install.

Use Swagger/OpenAPI CLI to validate openapi.json/openapi.yaml file, as the middleware assumes it to be valid.

Usage

Basic usage with Slim Framework.

Basic usage with Zend Expressive.

Options

The options array is passed to the middleware when it's constructed.

type format default description
additionalParameters bool false Allow additional parameters in query
beforeHandler callable null Instructions below
errorHandler callable null Instructions below
exampleResponse bool false Return example response from openapi.json/openapi.yaml if route implementation is empty
missingFormatException bool true Throw an exception if a format validator is missing
pathNotFoundException bool true Throw an exception if the path is not found in openapi.json/openapi.yaml
setDefaultParameters bool false Set the default parameter values for missing parameters and alter the request object
strictEmptyArrayValidation bool false Consider empty array when object is expected as validation error
stripResponse bool false Strip additional attributes from response to prevent response validation error
stripResponseHeaders bool false Strip additional headers from response to prevent response validation error
validateError bool false Should the error response be validated
validateRequest bool true Should the request be validated
validateResponse bool true Should the response's body be validated
validateResponseHeaders bool false Should the response's headers be validated
validateSecurity callable null Instructions below

beforeHandler

If defined, the function is called when the request validation fails before the next incoming middleware is called. You can use this to alter the request before passing it to the next incoming middleware in the stack. If it returns anything else than \Psr\Http\Message\ServerRequestInterface an exception will be thrown. The array $errors is an array containing all the validation errors.

errorHandler

If defined, the function is called instead of the default error handler. If it returns anything else than Psr\Http\Message\ResponseInterface it will fallback to the default error handler.

validateSecurity

If defined, the callback can return Psr\Http\Message\ResponseInterface if the operation is not allowed. $type can be none, http or apiKey.

Formats

There are two ways to validate formats not defined in the OAS specification. You can implement a custom format validator and add it to the middleware, or use the build in support for the Respect Validation libray.

Custom validator

Respect Validation

You can use all the validators just by setting the format property in your openapi.json/openapi.yaml file.

The country-code value will resolve to the v::countryCode() validator.

You can also pass arguments to the validator defined in the format attribute:

or

License

The OpenAPI Validation Middleware is licensed under the MIT license. See License File for more information.


All versions of openapi-validation-middleware with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
ext-json Version *
ckr/arraymerger Version ^2.0|^3.0
hkarlstrom/openapi-reader Version ^0.5
opis/json-schema Version ^2.3
psr/http-message Version ^1.0
psr/http-server-middleware Version ^1.0
respect/validation Version ^1.1
tuupola/callable-handler Version ^0.4.0|^1.0.0
tuupola/http-factory Version ^1.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package hkarlstrom/openapi-validation-middleware contains the following files

Loading the files please wait ....