Download the PHP package radebatz/openapi-verifier without Composer

On this page you can find all versions of the php package radebatz/openapi-verifier. 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-verifier

openapi-verifier

build Coverage Status License: MIT

Introduction

Verifies API responses against an OpenAPI specification. A response body that does not match its documented schema is reported as a mismatch, so the specification and the API cannot drift apart unnoticed.

Supported ways to hook in:

Requirements

Installation

You can use composer or simply download the release.

Composer

The preferred method is via composer. Follow the installation instructions if you do not already have composer installed.

Once composer is installed, execute the following command in your project root to install this library:

After that all required classes should be available in your project.

Some features need further packages, such as a framework adapter or YAML support. They are listed as suggestions, and composer suggests radebatz/openapi-verifier shows them.

Usage

The verifier

OpenApiVerifier checks a response against the specification. It needs no test case and no framework, so anything that sees a request and its response can use it.

The specification can be a JSON or YAML file, or an already decoded object.

How the response is looked up:

Bodies are validated with opis/json-schema, which supports JSON Schema 2020-12, the dialect of OpenAPI 3.1. OpenAPI 3.0 documents are translated first: nullable and the boolean form of exclusiveMinimum and exclusiveMaximum become their 2020-12 equivalents.

Another engine can be used by passing a Schema\SchemaValidator to the verifier. It gets each schema as the document writes it, together with the document's OpenAPI version, so it can handle 3.0 its own way or use Schema\OpenApi30Translator.

A mismatch carries one Schema\SchemaError per problem, with a JSON pointer into the body, the failing keyword and a message. getErrorSummary() groups them:

What is verified

Only response bodies are verified. Requests, parameters and response headers are not checked.

A response is only verified if the specification has a schema for it. A path, method or status code without one is skipped: verify() returns false and the adapters do nothing.

The body is validated against that schema as written:

Guzzle and PSR-18 clients

Verifying on the client side needs no framework. It works against a running server, a mock handler or anything else a client can talk to.

Guzzle: push the middleware onto the handler stack. A response that does not match makes the request throw OpenApiSchemaMismatchException.

PSR-18: wrap any Psr\Http\Client\ClientInterface, Guzzle's included.

Either way the response body is left at its start, so it can be read as usual afterwards.

Manual verification

The VerifiesOpenApi trait can be used directly and customized in 3 ways in order to provide the reqired OpenApi specifications:

PSR-15 middleware

Any PSR-15 stack (Slim, Mezzio and others) can verify its responses with the middleware. A response that does not match throws OpenApiSchemaMismatchException. An optional callback is called with the exception and the response first, to report the mismatch in a way of your own.

Laravel adapter

The adapter will try to resolve the specification dynamically in this order:

The code expects to be in the context of a Laravel Test\TestCase.

Slim adapter

The adapter will try to resolve the specification dynamically in this order:

Simplest way is to register the verifier in the Tests\Functional\BaseTestCase.

The adapter adds the PSR-15 middleware below, and a mismatch fails the test with the error summary and the response body.

Upgrading from 2.x

Requirements

Validation

API

Adapters

License

The openapi-verifier project is released under the MIT license.


All versions of openapi-verifier with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
ext-json Version *
nyholm/psr7 Version ^1.1
nyholm/psr7-server Version ^1.0
opis/json-schema Version ^2.4
psr/http-client Version ^1.0
psr/http-message Version ^2.0
psr/http-server-middleware Version ^1.0
symfony/psr-http-message-bridge Version ^6.0 || ^7.0
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 radebatz/openapi-verifier contains the following files

Loading the files please wait ...