Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: OpenAPI 3.1 #128

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: CI

on:
push:
branches: [ master ]
branches: [ master, openapi-31 ]
pull_request:
branches: [ master ]
branches: [ master, openapi-31 ]

jobs:
phpunit:
Expand Down
9 changes: 6 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ stan:
$(DOCKER_PHP) php $(PHPARGS) vendor/bin/phpstan analyse -l 5 src

# copy openapi3 json schema
schemas/openapi-v3.0.json: vendor/oai/openapi-specification/schemas/v3.0/schema.json
schemas/openapi-v3.0.json: vendor/oai/openapi-specification-3.0/schemas/v3.0/schema.json
cp $< $@

schemas/openapi-v3.0.yaml: vendor/oai/openapi-specification/schemas/v3.0/schema.yaml
schemas/openapi-v3.0.yaml: vendor/oai/openapi-specification-3.0/schemas/v3.0/schema.yaml
cp $< $@
schemas/openapi-v3.1.json: vendor/oai/openapi-specification-3.1/schemas/v3.1/schema.json
cp $< $@
schemas/openapi-v3.1.yaml: vendor/oai/openapi-specification-3.1/schemas/v3.1/schema.yaml
cp $< $@

php-cs-fixer.phar:
Expand Down
54 changes: 8 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# php-openapi

Read and write [OpenAPI](https://www.openapis.org/) 3.0.x YAML and JSON files and make the content accessible in PHP objects.
Read and write [OpenAPI](https://www.openapis.org/) 3.x YAML and JSON files and make the content accessible in PHP objects.

It also provides a CLI tool for validating and converting OpenAPI 3.0.x Description files.
It also provides a CLI tool for validating and converting OpenAPI 3.x Description files.

Supported OpenAPI versions:

- 3.0.x
- 3.1.x

[![Latest Stable Version](https://poser.pugx.org/cebe/php-openapi/v/stable)](https://packagist.org/packages/cebe/php-openapi)
[![Total Downloads](https://poser.pugx.org/cebe/php-openapi/downloads)](https://packagist.org/packages/cebe/php-openapi)
Expand Down Expand Up @@ -222,7 +227,7 @@ $openapi->resolveReferences(

The library provides simple validation operations, that check basic OpenAPI spec requirements.
This is the same as "structural errors found while reading the API Description file" from the CLI tool.
This validation does not include checking against the OpenAPI v3.0 JSON schema, this is only implemented in the CLI.
This validation does not include checking against the OpenAPI v3.0/v3.1 JSON schemas, this is only implemented in the CLI.

```
// return `true` in case no errors have been found, `false` in case of errors.
Expand All @@ -235,48 +240,6 @@ $errors = $openapi->getErrors();
> but the list of errors given may not be complete. Also a passing validation does not necessarily indicate a completely
> valid spec.


## Completeness

This library is currently work in progress, the following list tracks completeness:

- [x] read OpenAPI 3.0 JSON
- [x] read OpenAPI 3.0 YAML
- [ ] OpenAPI 3.0 Schema
- [x] OpenAPI Object
- [x] Info Object
- [x] Contact Object
- [x] License Object
- [x] Server Object
- [x] Server Variable Object
- [x] Components Object
- [x] Paths Object
- [x] Path Item Object
- [x] Operation Object
- [x] External Documentation Object
- [x] Parameter Object
- [x] Request Body Object
- [x] Media Type Object
- [x] Encoding Object
- [x] Responses Object
- [x] Response Object
- [x] Callback Object
- [x] Example Object
- [x] Link Object
- [ ] [Runtime Expressions](https://github.com/OAI/OpenAPI-Specification/blob/3.0.2/versions/3.0.2.md#runtime-expressions)
- [x] Header Object
- [x] Tag Object
- [x] Reference Object
- [x] Schema Object
- [x] load/read
- [ ] validation
- [x] Discriminator Object
- [x] XML Object
- [x] Security Scheme Object
- [x] OAuth Flows Object
- [x] OAuth Flow Object
- [x] Security Requirement Object

# Development

You may use the docker environment for local development:
Expand All @@ -286,7 +249,6 @@ You may use the docker environment for local development:
make IN_DOCKER=1 test
...


# Support

**Need help with your API project?**
Expand Down
12 changes: 9 additions & 3 deletions bin/php-openapi
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,22 @@ switch ($command) {

// Validate

// OpenAPI version check
$openApiVersion = $openApi->getMajorVersion();
if ($openApiVersion === \cebe\openapi\spec\OpenApi::VERSION_UNSUPPORTED) {
error("Unsupported OpenAPI version: " . $openApi->openapi);
}

$openApi->validate();
$errors = array_merge($errors, $openApi->getErrors());

$validator = new JsonSchema\Validator;
$openApiData = $openApi->getSerializableData();
$validator->validate($openApiData, (object)['$ref' => 'file://' . dirname(__DIR__) . '/schemas/openapi-v3.0.json']);
$validator->validate($openApiData, (object)['$ref' => 'file://' . dirname(__DIR__) . "/schemas/openapi-v{$openApiVersion}.json"]);

if ($validator->isValid() && empty($errors)) {
if(!$silentMode) {
print_formatted("The supplied API Description \B\Gvalidates\C against the OpenAPI v3.0 schema.\n", STDERR);
print_formatted("The supplied API Description \B\Gvalidates\C against the OpenAPI v{$openApiVersion} schema.\n", STDERR);
}
exit(0);
}
Expand All @@ -163,7 +169,7 @@ switch ($command) {
}
}
if (!$validator->isValid()) {
print_formatted("\BOpenAPI v3.0 schema violations:\C\n", STDERR);
print_formatted("\BOpenAPI v{$openApiVersion} schema violations:\C\n", STDERR);
$errors = $validator->getErrors();
foreach ($errors as $error) {
// hide some errors triggered by other errors further down the path
Expand Down
21 changes: 18 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
"require-dev": {
"cebe/indent": "*",
"phpunit/phpunit": "^6.5 || ^7.5 || ^8.5 || ^9.4",
"oai/openapi-specification": "3.0.3",

"oai/openapi-specification-3.0": "3.0.3",
"oai/openapi-specification-3.1": "3.1.0",

"mermade/openapi3-examples": "1.0.0",
"apis-guru/openapi-directory": "1.0.0",
"nexmo/api-specification": "1.0.0",
Expand All @@ -52,7 +55,7 @@
{
"type": "package",
"package": {
"name": "oai/openapi-specification",
"name": "oai/openapi-specification-3.0",
"version": "3.0.3",
"source": {
"url": "https://github.com/OAI/OpenAPI-Specification",
Expand All @@ -61,6 +64,18 @@
}
}
},
{
"type": "package",
"package": {
"name": "oai/openapi-specification-3.1",
"version": "3.1.0",
"source": {
"url": "https://github.com/OAI/OpenAPI-Specification",
"type": "git",
"reference": "v3.1.1-dev"
}
}
},
{
"type": "package",
"package": {
Expand All @@ -69,7 +84,7 @@
"source": {
"url": "https://github.com/Mermade/openapi3-examples",
"type": "git",
"reference": "3e8740c4994310a5d6a35d9b19e405862326f149"
"reference": "9c2997e1a25919a8182080cc43a4db06d2dc775d"
}
}
},
Expand Down
Loading