Download the PHP package benmorel/openapi-schema-to-json-schema without Composer

On this page you can find all versions of the php package benmorel/openapi-schema-to-json-schema. 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-schema-to-json-schema

OpenAPI schema to JSON Schema

A PHP library to convert an OpenAPI schema or parameter object to JSON Schema.

Build Status Coverage Status Latest Stable Version License

This is a port of the nodejs package by @mikunn.

It currently converts from OpenAPI 3.0 to JSON Schema Draft 4.

Why?

OpenAPI is a specification for describing RESTful APIs. OpenAPI 3.0 allows us to describe the structures of request and response payloads in a detailed manner. This would, theoretically, mean that we should be able to automatically validate request and response payloads. However, at the time of writing there aren't many validators around.

The good news is that there are many validators for JSON Schema, such as justinrainbow/json-schema. The bad news is that OpenAPI 3.0 is not entirely compatible with JSON Schema. The Schema object of OpenAPI 3.0 is an extended subset of JSON Schema Specification Wright Draft 00 with some differences.

The purpose of this project is to fill the gap by doing the conversion between these two formats.

Features

NOTE: $refs are not dereferenced. Use a dereferencer prior to using this package.

Installation

This library is installable via Composer:

Requirements

This library requires:

There is no dependency on third-party libraries.

Project status & release process

The current releases are numbered 0.x.y. When a non-breaking change is introduced (adding new methods, optimizing existing code, etc.), y is incremented.

When a breaking change is introduced, a new 0.x version cycle is always started.

It is therefore safe to lock your project to a given release cycle, such as 0.1.*.

If you need to upgrade to a newer release cycle, check the release history for a list of changes introduced by each further 0.x.0 version.

Converting an OpenAPI schema

Here's a small example to get the idea:

The example prints out:

Converting an OpenAPI parameter

OpenAPI parameters can be converted:

The result is as follows:

When a parameter has several schemas (one per MIME type) a map is returned instead:

would be converted to:

Options

Both Convert::openapiSchemaToJsonSchema() and Convert::openapiParameterToJsonSchema() accept a $options associative array as the second argument, with the following keys:

cloneSchema (bool)

If set to false, converts the provided schema in place. If true, clones the schema by converting it to JSON and back. The overhead of the cloning is usually negligible. Defaults to true.

dateToDateTime (bool)

This is false by default and leaves date format as is. If set to true, sets format: 'date' to format: 'date-time'.

For example:

is converted to:

keepNotSupported (array)

By default, the following fields are removed from the result schema: nullable, discriminator, readOnly, writeOnly, xml, externalDocs, example and deprecated as they are not supported by JSON Schema Draft 4. Provide an array of the ones you want to keep (as strings) and they won't be removed.

removeReadOnly (bool)

If set to true, will remove properties set as readOnly. If the property is set as required, it will be removed from the required array as well. The property will be removed even if readOnly is set to be kept with keepNotSupported.

removeWriteOnly (bool)

Similar to removeReadOnly, but for writeOnly properties.

supportPatternProperties (bool)

If set to true and x-patternProperties property is present, change x-patternProperties to patternProperties and call patternPropertiesHandler. If patternPropertiesHandler is not defined, call the default handler. See patternPropertiesHandler for more information.

patternPropertiesHandler (function)

Provide a function to handle pattern properties and set supportPatternProperties to take effect. The function takes the schema where x-patternProperties is defined on the root level. At this point x-patternProperties is changed to patternProperties. It must return the modified schema.

If the handler is not provided, the default handler is used. If additionalProperties is set and is an object, the default handler sets it to false if the additionalProperties object has deep equality with a pattern object inside patternProperties. This is because we might want to define additionalProperties in OpenAPI spec file, but want to validate against a pattern. The pattern would turn out to be useless if additionalProperties of the same structure were allowed. Create you own handler to override this functionality.

See tests/PatternPropertiesTest.php for examples of how this works.


All versions of openapi-schema-to-json-schema with dependencies

PHP Build Version
Package Version
Requires php Version ^7.2 || ^8.0
ext-json Version *
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 benmorel/openapi-schema-to-json-schema contains the following files

Loading the files please wait ....