Skip to content

Commit fe0d912

Browse files
authored
Merge pull request #1 from DEVizzent/openapi-31
Openapi 31
2 parents 020d72b + 684aac0 commit fe0d912

14 files changed

Lines changed: 2522 additions & 112 deletions

File tree

.github/workflows/php.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ name: CI
22

33
on:
44
push:
5-
branches: [ master ]
5+
branches: [ master, openapi-31 ]
66
pull_request:
7-
branches: [ master ]
7+
branches: [ master, openapi-31 ]
88

99
jobs:
1010
phpunit:

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,13 @@ stan:
6363
$(DOCKER_PHP) php $(PHPARGS) vendor/bin/phpstan analyse -l 5 src
6464

6565
# copy openapi3 json schema
66-
schemas/openapi-v3.0.json: vendor/oai/openapi-specification/schemas/v3.0/schema.json
66+
schemas/openapi-v3.0.json: vendor/oai/openapi-specification-3.0/schemas/v3.0/schema.json
6767
cp $< $@
68-
69-
schemas/openapi-v3.0.yaml: vendor/oai/openapi-specification/schemas/v3.0/schema.yaml
68+
schemas/openapi-v3.0.yaml: vendor/oai/openapi-specification-3.0/schemas/v3.0/schema.yaml
69+
cp $< $@
70+
schemas/openapi-v3.1.json: vendor/oai/openapi-specification-3.1/schemas/v3.1/schema.json
71+
cp $< $@
72+
schemas/openapi-v3.1.yaml: vendor/oai/openapi-specification-3.1/schemas/v3.1/schema.yaml
7073
cp $< $@
7174

7275
php-cs-fixer.phar:

README.md

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
# php-openapi
22

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

5-
It also provides a CLI tool for validating and converting OpenAPI 3.0.x Description files.
5+
It also provides a CLI tool for validating and converting OpenAPI 3.x Description files.
6+
7+
Supported OpenAPI versions:
8+
9+
- 3.0.x
10+
- 3.1.x
611

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

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

227232
```
228233
// return `true` in case no errors have been found, `false` in case of errors.
@@ -235,48 +240,6 @@ $errors = $openapi->getErrors();
235240
> but the list of errors given may not be complete. Also a passing validation does not necessarily indicate a completely
236241
> valid spec.
237242
238-
239-
## Completeness
240-
241-
This library is currently work in progress, the following list tracks completeness:
242-
243-
- [x] read OpenAPI 3.0 JSON
244-
- [x] read OpenAPI 3.0 YAML
245-
- [ ] OpenAPI 3.0 Schema
246-
- [x] OpenAPI Object
247-
- [x] Info Object
248-
- [x] Contact Object
249-
- [x] License Object
250-
- [x] Server Object
251-
- [x] Server Variable Object
252-
- [x] Components Object
253-
- [x] Paths Object
254-
- [x] Path Item Object
255-
- [x] Operation Object
256-
- [x] External Documentation Object
257-
- [x] Parameter Object
258-
- [x] Request Body Object
259-
- [x] Media Type Object
260-
- [x] Encoding Object
261-
- [x] Responses Object
262-
- [x] Response Object
263-
- [x] Callback Object
264-
- [x] Example Object
265-
- [x] Link Object
266-
- [ ] [Runtime Expressions](https://github.com/OAI/OpenAPI-Specification/blob/3.0.2/versions/3.0.2.md#runtime-expressions)
267-
- [x] Header Object
268-
- [x] Tag Object
269-
- [x] Reference Object
270-
- [x] Schema Object
271-
- [x] load/read
272-
- [ ] validation
273-
- [x] Discriminator Object
274-
- [x] XML Object
275-
- [x] Security Scheme Object
276-
- [x] OAuth Flows Object
277-
- [x] OAuth Flow Object
278-
- [x] Security Requirement Object
279-
280243
# Development
281244

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

289-
290252
# Support
291253

292254
**Need help with your API project?**

bin/php-openapi

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,16 +131,22 @@ switch ($command) {
131131

132132
// Validate
133133

134+
// OpenAPI version check
135+
$openApiVersion = $openApi->getMajorVersion();
136+
if ($openApiVersion === \cebe\openapi\spec\OpenApi::VERSION_UNSUPPORTED) {
137+
error("Unsupported OpenAPI version: " . $openApi->openapi);
138+
}
139+
134140
$openApi->validate();
135141
$errors = array_merge($errors, $openApi->getErrors());
136142

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

141147
if ($validator->isValid() && empty($errors)) {
142148
if(!$silentMode) {
143-
print_formatted("The supplied API Description \B\Gvalidates\C against the OpenAPI v3.0 schema.\n", STDERR);
149+
print_formatted("The supplied API Description \B\Gvalidates\C against the OpenAPI v{$openApiVersion} schema.\n", STDERR);
144150
}
145151
exit(0);
146152
}
@@ -163,7 +169,7 @@ switch ($command) {
163169
}
164170
}
165171
if (!$validator->isValid()) {
166-
print_formatted("\BOpenAPI v3.0 schema violations:\C\n", STDERR);
172+
print_formatted("\BOpenAPI v{$openApiVersion} schema violations:\C\n", STDERR);
167173
$errors = $validator->getErrors();
168174
foreach ($errors as $error) {
169175
// hide some errors triggered by other errors further down the path

composer.json

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
"require-dev": {
2727
"cebe/indent": "*",
2828
"phpunit/phpunit": "^6.5 || ^7.5 || ^8.5 || ^9.4",
29-
"oai/openapi-specification": "3.0.3",
29+
30+
"oai/openapi-specification-3.0": "3.0.3",
31+
"oai/openapi-specification-3.1": "3.1.0",
32+
3033
"mermade/openapi3-examples": "1.0.0",
3134
"apis-guru/openapi-directory": "1.0.0",
3235
"nexmo/api-specification": "1.0.0",
@@ -52,7 +55,7 @@
5255
{
5356
"type": "package",
5457
"package": {
55-
"name": "oai/openapi-specification",
58+
"name": "oai/openapi-specification-3.0",
5659
"version": "3.0.3",
5760
"source": {
5861
"url": "https://github.com/OAI/OpenAPI-Specification",
@@ -61,6 +64,18 @@
6164
}
6265
}
6366
},
67+
{
68+
"type": "package",
69+
"package": {
70+
"name": "oai/openapi-specification-3.1",
71+
"version": "3.1.0",
72+
"source": {
73+
"url": "https://github.com/OAI/OpenAPI-Specification",
74+
"type": "git",
75+
"reference": "v3.1.1-dev"
76+
}
77+
}
78+
},
6479
{
6580
"type": "package",
6681
"package": {
@@ -69,7 +84,7 @@
6984
"source": {
7085
"url": "https://github.com/Mermade/openapi3-examples",
7186
"type": "git",
72-
"reference": "3e8740c4994310a5d6a35d9b19e405862326f149"
87+
"reference": "9c2997e1a25919a8182080cc43a4db06d2dc775d"
7388
}
7489
}
7590
},

0 commit comments

Comments
 (0)