DataModels for OpenAPI 3.0.* specification.
- PHP 8.1 or higher.
Install Zerotoprod\DataModelOpenapi30 via Composer:
composer require zero-to-prod/data-model-openapi30This will add the package to your project’s dependencies and create an autoloader entry for it.
use Zerotoprod\DataModelOpenapi30\OpenApi;
$OpenApi = OpenApi::from(json_decode($json, true));
$OpenApi->components->schemas['pet']->description;You can directly import these files into your project like this:
./vendor/bin/data-model-openapi30 app/DataModelOpenapi30This section describes the structure of the OpenAPI Description format
This is the root object of the OpenAPI Description.
| Field Name | Type | Status |
|---|---|---|
| openapi | string |
✅ |
| info | Info Object |
✅ |
| servers | [Server Object] |
✅ |
| paths | Paths Object |
✅ |
| components | Components Object |
✅ |
| security | Security Requirement Object |
✅ |
| tags | [Tag Object] |
✅ |
| externalDocs | External Documentation Object |
✅ |
The object provides metadata about the API.
| Field Name | Type | Status |
|---|---|---|
| title | string |
✅ |
| description | string |
✅ |
| termsOfService | string |
✅ |
| contact | Contact Object |
✅ |
| license | License Object |
✅ |
| version | string |
✅ |
Contact information for the exposed API.
| Field | Type | Status |
|---|---|---|
| name | string |
✅ |
| url | string |
✅ |
email |
✅ |
License information for the exposed API.
| Field | Type | Status |
|---|---|---|
| name | string |
✅ |
| url | string |
✅ |
An object representing a Server.
| Field Name | Type | Status |
|---|---|---|
| url | string |
✅ |
| description | string |
✅ |
| variables | Map[string, Server Variable Object] |
✅ |
An object representing a Server Variable for server URL template substitution.
| Field Name | Type | Status |
|---|---|---|
| enum | [string] |
✅ |
| default | string |
✅ |
| description | string |
✅ |
Holds a set of reusable objects for different aspects of the OAS.
| Field Name | Type | Status |
|---|---|---|
| schemas | Map[string, Schema Object | Reference Object] |
✅ |
| responses | Map[string, Response Object | Reference Object] |
✅ |
| parameters | Map[string, Parameter Object | Reference Object] |
✅ |
| examples | Map[string, Example Object | Reference Object] |
✅ |
| requestBodies | Map[string, Request Body Object | Reference Object] |
✅ |
| headers | Map[string, Header Object | Reference Object] |
✅ |
| securitySchemes | Map[string, Security Scheme Object | Reference Object] |
✅ |
| links | Map[string, Link Object | Reference Object] |
✅ |
| callbacks | Map[string, Callback Object | Reference Object] |
✅ |
Holds the relative paths to the individual endpoints and their operations.
| Field Name | Type | Status |
|---|---|---|
| /{path} | Path Item Object | ✅ |
Describes the operations available on a single path.
| Field Name | Type | Status |
|---|---|---|
| $ref | string |
✅ |
| summary | string |
✅ |
| description | string |
✅ |
| get | Operation Object |
✅ |
| put | Operation Object |
✅ |
| post | Operation Object |
✅ |
| delete | Operation Object |
✅ |
| options | Operation Object |
✅ |
| head | Operation Object |
✅ |
| patch | Operation Object |
✅ |
| trace | Operation Object |
✅ |
| servers | Server Object |
✅ |
| parameters | [Parameter Object | Reference Object] |
✅ |
Describes a single API operation on a path.
| Field Name | Type | Status |
|---|---|---|
| tags | [string] |
✅ |
| summary | string |
✅ |
| description | string |
✅ |
| externalDocs | External Documentation Object |
✅ |
| operationId | string |
✅ |
| parameters | [Parameter Object | Reference Object] |
✅ |
| requestBody | Request Body Object | Reference Object |
✅ |
| responses | Responses Object |
✅ |
| callbacks | Map[string, Callback Object | Reference Object] |
✅ |
| deprecated | boolean |
✅ |
| security | [Security Requirement Object] |
✅ |
| servers | [Server Object] |
✅ |
Allows referencing an external resource for extended documentation.
| Field Name | Type | Status |
|---|---|---|
| description | string |
✅ |
| url | string |
✅ |
Describes a single operation parameter.
The rules for serialization of the parameter are specified in one of two ways. Parameter Objects MUST include either a content field or a schema
field, but not both.
These fields MAY be used with either content or schema.
| Field Name | Type | Status |
|---|---|---|
| name | string |
✅ |
| in | string |
✅ |
| description | string |
✅ |
| required | boolean |
✅ |
| deprecated | boolean |
✅ |
| allowEmptyValue | [boolean] |
✅ |
For simpler scenarios, a schema and style can describe the structure and syntax of the parameter.
| Field Name | Type | Status |
|---|---|---|
| style | string |
✅ |
| explode | boolean |
✅ |
| allowReserved | boolean |
✅ |
| schema | Schema Object | Reference Object |
✅ |
| example | Any | ✅ |
| examples | Map[ string, Example Object | Reference Object] |
✅ |
| Field Name | Type | Status |
|---|---|---|
| content | Map[string, Media Type Object] |
✅ |
Describes a single request body.
| Field Name | Type | Status |
|---|---|---|
| description | string |
✅ |
| content | Map[string, Media Type Object] |
✅ |
| required | boolean |
✅ |
Each Media Type Object provides schema and examples for the media type identified by its key.
| Field Name | Type | Status |
|---|---|---|
| schema | Schema Object | Reference Object |
✅ |
| example | Any | ✅ |
| examples | Map[string, Example Object | Reference Object] |
✅ |
| encoding | Map[string, Encoding Object] |
✅ |
A single encoding definition applied to a single schema property.
These fields MAY be used either with or without the RFC6570-style serialization fields defined in the next section below.
| Field Name | Type | Status |
|---|---|---|
| contentType | string |
✅ |
| headers | Map[string, Header Object | Reference Object] |
✅ |
| Field Name | Type | Status |
|---|---|---|
| style | string |
✅ |
| explode | boolean |
✅ |
| allowReserved | boolean |
✅ |
A container for the expected responses of an operation. The container maps an HTTP response code to the expected response.
| Field Name | Type | Status |
|---|---|---|
| default | Response Object | Reference Object |
✅ |
| Field Name | Type | Status |
|---|---|---|
| HTTP Status Code | Response Object | Reference Object |
✅ |
Describes a single response from an API operation, including design-time, static links to operations based on the response.
| Field Name | Type | Status |
|---|---|---|
| description | string |
✅ |
| headers | Map[string, Header Object | Reference Object] |
✅ |
| content | Map[string, Media Type Object] |
✅ |
| links | Map[string, Link Object | Reference Object] |
✅ |
An object grouping an internal or external example value with basic summary and description metadata.
| Field Name | Type | Status |
|---|---|---|
| summary | string |
✅ |
| description | string |
✅ |
| value | Any | ✅ |
| externalValue | string |
✅ |
The Link Object represents a possible design-time link for a response.
| Field Name | Type | Status |
|---|---|---|
| operationRef | string |
✅ |
| operationId | string |
✅ |
| parameters | Map[string, Any | {expression}] |
✅ |
| requestBody | Any | {expression} | ✅ |
| description | string |
✅ |
| server | Server Object |
✅ |
Describes a single header for HTTP responses and for individual parts in multipart representations.
These fields MAY be used with either content or schema.
| Field Name | Type | Status |
|---|---|---|
| description | string |
✅ |
| required | boolean |
✅ |
| deprecated | boolean |
✅ |
For simpler scenarios, a schema and style can describe the structure and syntax of the header.
| Field Name | Type | Status |
|---|---|---|
| style | string |
✅ |
| explode | boolean |
✅ |
| schema | Schema Object | Reference Object |
✅ |
| example | Any | ✅ |
| examples | Map[string, Example Object | Reference Object] |
✅ |
For more complex scenarios, the content field can define the media type and schema of the header, as well as give examples of its use.
| Field Name | Type | Status |
|---|---|---|
| content | Map[string, Media Type Object] |
✅ |
Adds metadata to a single tag that is used by the Operation Object. It is not mandatory to have a Tag Object per tag defined in the Operation Object instances.
| Field | Type | Status |
|---|---|---|
| name | string |
✅ |
| description | string |
✅ |
| description | External Documentation Object |
✅ |
A simple object to allow referencing other components in the OpenAPI Description, internally and externally.
| Field | Type | Status |
|---|---|---|
| $ref | string |
✅ |
The Schema Object allows the definition of input and output data types.
| Field Name | Type | Status |
|---|---|---|
| title | string |
✅ |
| multipleOf | number |
✅ |
| maximum | number |
✅ |
| exclusiveMaximum | boolean |
✅ |
| minimum | number |
✅ |
| exclusiveMinimum | boolean |
✅ |
| maxLength | integer |
✅ |
| minLength | integer |
✅ |
| pattern | string |
✅ |
| maxItems | integer |
✅ |
| minItems | integer |
✅ |
| uniqueItems | boolean |
✅ |
| maxProperties | integer |
✅ |
| minProperties | integer |
✅ |
| required | array |
✅ |
| enum | array |
✅ |
| type | string |
✅ |
| allOf | Reference Object | Schema Object |
✅ |
| oneOf | Reference Object | Schema Object |
✅ |
| anyOf | Reference Object | Schema Object |
✅ |
| not | Reference Object | Schema Object |
✅ |
| items | Reference Object | Schema Object |
✅ |
| properties | Reference Object | Schema Object |
✅ |
| additionalProperties | boolean |Reference Object | Schema Object |
✅ |
| description | string |
✅ |
| format | string |
✅ |
| format | Any |
✅ |
| Field Name | Type | Status |
|---|---|---|
| nullable | boolean |
✅ |
| discriminator | Discriminator Object |
✅ |
| readOnly | boolean |
✅ |
| writeOnly | boolean |
✅ |
| xml | XML Object |
✅ |
| externalDocs | External Documentation Object |
✅ |
| example | Any | ✅ |
| deprecated | boolean |
✅ |
When request bodies or response payloads may be one of a number of different schemas, a Discriminator Object gives a hint about the expected schema of the document.
| Field Name | Type | Status |
|---|---|---|
| propertyName | string |
✅ |
| mapping | Map[string, string] |
✅ |
A metadata object that allows for more fine-tuned XML model definitions.
| Field Name | Type | Status |
|---|---|---|
| name | string |
✅ |
| namespace | string |
✅ |
| prefix | string |
✅ |
| attribute | boolean |
✅ |
| wrapped | boolean |
✅ |
Defines a security scheme that can be used by the operations.
| Field Name | Type | Status |
|---|---|---|
| type | string |
✅ |
| description | string |
✅ |
| name | string |
✅ |
| in | string |
✅ |
| scheme | string |
✅ |
| bearerFormat | string |
✅ |
| flows | string |
✅ |
| openIdConnectUrl | string |
✅ |
Allows configuration of the supported OAuth Flows.
| Field Name | Type | Status |
|---|---|---|
| implicit | OAuth Flow Object |
✅ |
| password | OAuth Flow Object |
✅ |
| clientCredentials | OAuth Flow Object |
✅ |
| authorizationCode | OAuth Flow Object |
✅ |
Defines a security scheme that can be used by the operations.
| Field Name | Type | Status |
|---|---|---|
| authorizationUrl | string |
✅ |
| tokenUrl | string |
✅ |
| refreshUrl | string |
✅ |
| scopes | Map[string, string] |
✅ |
Contributions, issues, and feature requests are welcome! Feel free to check the issues page if you want to contribute.
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch). - Commit changes (
git commit -m 'Add some feature'). - Push to the branch (
git push origin feature-branch). - Create a new Pull Request.
