Skip to content

Commit 684aac0

Browse files
committed
Merge branch 'master' into openapi-31
* master: (22 commits) Catch recursion when resolving inside included file Improve Responses resolving references Fixes default value for exclusiveMinimum and exclusiveMaximum more specific deprecation add hasPropertyValue() method add comments, optimize tests for cebe#125 During serialization convert empty Map fields to empty Objects Add test to demonstrate OpenAPI v3.0 schema validation fails with empty Path properties yarn upgrade Added docker environment for local development Add symfony 6 support (cebe#151) Bump node-fetch from 2.6.1 to 2.6.7 (cebe#149) Fix CI badge in Readme (cebe#150) Temporarily skip broken test (cebe#145) Run speccy through yarn Add windows and macos cases Temporarily skip broken test Rework CI Run all tests (cebe#136) Drop licence badge from readme (cebe#137) ... Conflicts: README.md composer.json src/SpecBaseObject.php tests/ReaderTest.php
2 parents c88cb31 + 43044d5 commit 684aac0

21 files changed

+873
-464
lines changed

.github/workflows/code-style.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Code Style
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
code-style:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- name: Install PHP
16+
uses: shivammathur/setup-php@v2
17+
with:
18+
php-version: 7.1
19+
20+
- name: Check code style
21+
run: make check-style

.github/workflows/php.yml

Lines changed: 40 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: PHP Composer
1+
name: CI
22

33
on:
44
push:
@@ -7,35 +7,49 @@ on:
77
branches: [ master, openapi-31 ]
88

99
jobs:
10-
build:
11-
10+
phpunit:
11+
name: Tests
1212
strategy:
1313
fail-fast: false
1414
matrix:
15-
# os: [ubuntu-latest, macos-latest, windows-latest]
1615
os: [ubuntu-latest]
17-
php: ['7.1', '7.2', '7.3', '7.4', '8.0']
18-
# max 4.4.16, see https://github.com/symfony/symfony/issues/39521
19-
# max 5.1.8, see https://github.com/symfony/symfony/issues/39521
20-
yaml: ['5.2.9', '5.1.11', '4.4.24', '^3.4']
16+
php:
17+
- "7.1"
18+
- "7.2"
19+
- "7.3"
20+
- "7.4"
21+
- "8.0"
22+
dependencies:
23+
- "lowest"
24+
- "highest"
25+
symfony-yaml: ['^3.4', '^4', '^5', '^6']
26+
include:
27+
- os: "windows-latest"
28+
php: "8.0"
29+
dependencies: "highest"
30+
symfony-yaml: '5.4.2'
31+
- os: "macos-latest"
32+
php: "8.0"
33+
dependencies: "highest"
34+
symfony-yaml: '^5'
2135
exclude:
22-
# Symfony YAML does not run on PHP 7.1
36+
# symfony/yaml v5 does not run on PHP 7.1
2337
- php: '7.1'
24-
yaml: '5.1.11'
38+
symfony-yaml: '^5'
39+
# symfony/yaml v6 does not run on PHP 7.*
2540
- php: '7.1'
26-
yaml: '5.2.9'
27-
include:
28-
- php: '7.4'
29-
os: windows-latest
30-
yaml: '5.2.9'
41+
symfony-yaml: '^6'
42+
- php: '7.2'
43+
symfony-yaml: '^6'
44+
- php: '7.3'
45+
symfony-yaml: '^6'
3146
- php: '7.4'
32-
os: macos-latest
33-
yaml: '5.2.9'
34-
47+
symfony-yaml: '^6'
48+
# symfony/yaml v3.4 is not compatible with PHP 8.0 but has no upper-bound, so it installs on it
49+
- php: '8.0'
50+
symfony-yaml: '^3.4'
3551

3652
runs-on: ${{ matrix.os }}
37-
env:
38-
YAML: ${{ matrix.yaml }}
3953

4054
steps:
4155
- uses: actions/checkout@v2
@@ -44,60 +58,22 @@ jobs:
4458
uses: shivammathur/setup-php@v2
4559
with:
4660
php-version: ${{ matrix.php }}
47-
ini-values: date.timezone='UTC'
4861
coverage: pcov
4962
tools: composer:v2
5063

51-
- name: Determine composer cache directory (Linux/MacOS)
52-
if: matrix.os != 'windows-latest'
53-
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV
54-
55-
- name: Determine composer cache directory (Windows)
56-
if: matrix.os == 'windows-latest'
57-
run: echo "COMPOSER_CACHE_DIR=~\AppData\Local\Composer" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
64+
- name: Require specific symfony/yaml version
65+
run: "composer require symfony/yaml:'${{ matrix.symfony-yaml }}' --prefer-dist --no-interaction --ansi --no-install"
5866

59-
- name: Cache dependencies installed with composer
60-
uses: actions/cache@v2
67+
- name: "Install dependencies with Composer"
68+
uses: "ramsey/composer-install@v2"
6169
with:
62-
path: ${{ env.COMPOSER_CACHE_DIR }}
63-
key: php${{ matrix.php }}-os${{ matrix.os }}-yaml${{ matrix.yaml }}-composer-${{ hashFiles('**/composer.json') }}
64-
65-
66-
- name: Validate composer.json and composer.lock
67-
run: composer validate --ansi
68-
69-
- name: Install dependencies (Linux/MacOS)
70-
if: matrix.os != 'windows-latest'
71-
run: |
72-
make install
73-
composer require symfony/yaml:"${YAML}" --prefer-dist --no-interaction --ansi
74-
75-
- name: Install dependencies (Windows)
76-
if: matrix.os == 'windows-latest'
77-
run: |
78-
composer install --prefer-dist --no-interaction --no-progress --ansi
79-
composer require symfony/yaml:5.1.8 --prefer-dist --no-interaction --ansi
70+
dependency-versions: "${{ matrix.dependencies }}"
8071

8172
- name: Validate test data
82-
if: matrix.os == 'ubuntu-latest'
8373
run: make lint
8474

85-
- name: PHP Stan analysis
86-
if: matrix.os == 'ubuntu-latest'
87-
run: make stan
88-
89-
- name: PHPUnit tests (Linux/MacOS)
90-
if: matrix.os != 'windows-latest'
75+
- name: PHPUnit tests
9176
run: make test
9277

93-
- name: PHPUnit tests (Windows)
94-
if: matrix.os == 'windows-latest'
95-
run: vendor/bin/phpunit --colors=always
96-
97-
- name: Check code style
98-
if: matrix.os == 'ubuntu-latest'
99-
run: make check-style
100-
10178
- name: Code coverage
102-
if: matrix.os == 'ubuntu-latest'
10379
run: make coverage

.github/workflows/phpstan.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: PHPStan
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
phpstan:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
15+
- name: Install PHP
16+
uses: shivammathur/setup-php@v2
17+
with:
18+
php-version: "7.1"
19+
tools: composer:v2
20+
21+
- name: "Install dependencies with Composer"
22+
uses: "ramsey/composer-install@v2"
23+
24+
- name: PHPStan analysis
25+
run: make stan

Makefile

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,61 @@ ifeq ($(XDEBUG),1)
66
XPHPARGS=-dzend_extension=xdebug.so -dxdebug.remote_enable=1 -dxdebug.remote_autostart=1
77
endif
88

9+
# Run make with IN_DOCKER=1 to run yarn and php commands in a docker container
10+
DOCKER_PHP=
11+
DOCKER_NODE=
12+
IN_DOCKER=0
13+
ifeq ($(IN_DOCKER),1)
14+
DOCKER_PHP=docker-compose run --rm php
15+
DOCKER_NODE=docker-compose run --rm -w /app node
16+
endif
17+
918
all:
19+
@echo "the following commands are available:"
20+
@echo ""
21+
@echo "make check-style # check code style"
22+
@echo "make fix-style # fix code style"
23+
@echo "make install # install dependencies"
24+
@echo "make test # run PHPUnit tests"
25+
@echo "make lint # check validity of test data"
26+
@echo "make stan # check code with PHPStan"
27+
@echo ""
28+
@echo "You may add the IN_DOCKER parameter to run a command inside of docker container and not directly."
29+
@echo "make IN_DOCKER=1 ..."
30+
1031

1132
check-style: php-cs-fixer.phar
1233
PHP_CS_FIXER_IGNORE_ENV=1 ./php-cs-fixer.phar fix src/ --diff --dry-run
1334

1435
fix-style: php-cs-fixer.phar
15-
vendor/bin/indent --tabs composer.json
16-
vendor/bin/indent --spaces .php_cs.dist
17-
./php-cs-fixer.phar fix src/ --diff
18-
19-
install:
20-
composer install --prefer-dist --no-interaction --no-progress --ansi
21-
yarn install
22-
23-
test:
24-
php $(PHPARGS) $(XPHPARGS) vendor/bin/phpunit --verbose --colors=always $(TESTCASE)
25-
php $(PHPARGS) $(XPHPARGS) bin/php-openapi validate tests/spec/data/recursion.json
26-
php $(PHPARGS) $(XPHPARGS) bin/php-openapi validate tests/spec/data/recursion2.yaml
27-
28-
lint:
29-
php $(PHPARGS) $(XPHPARGS) bin/php-openapi validate tests/spec/data/reference/playlist.json
30-
php $(PHPARGS) $(XPHPARGS) bin/php-openapi validate tests/spec/data/recursion.json
31-
php $(PHPARGS) $(XPHPARGS) bin/php-openapi validate tests/spec/data/recursion2.yaml
32-
node_modules/.bin/speccy lint tests/spec/data/reference/playlist.json
33-
node_modules/.bin/speccy lint tests/spec/data/recursion.json
36+
$(DOCKER_PHP) vendor/bin/indent --tabs composer.json
37+
$(DOCKER_PHP) vendor/bin/indent --spaces .php_cs.dist
38+
$(DOCKER_PHP) ./php-cs-fixer.phar fix src/ --diff
39+
40+
install: composer.lock yarn.lock
41+
$(DOCKER_PHP) composer install --prefer-dist --no-interaction --no-progress --ansi
42+
$(DOCKER_NODE) yarn install
43+
44+
test: unit test-recursion.json test-recursion2.yaml test-recursion3_index.yaml test-empty-maps.json
45+
46+
unit:
47+
$(DOCKER_PHP) php $(PHPARGS) $(XPHPARGS) vendor/bin/phpunit --verbose --colors=always $(TESTCASE)
48+
49+
# test specific JSON files in tests/spec/data/
50+
# e.g. test-recursion will run validation on tests/spec/data/recursion.json
51+
test-%: tests/spec/data/%
52+
$(DOCKER_PHP) php $(PHPARGS) $(XPHPARGS) bin/php-openapi validate $<
53+
54+
lint: install
55+
$(DOCKER_PHP) php $(PHPARGS) $(XPHPARGS) bin/php-openapi validate tests/spec/data/reference/playlist.json
56+
$(DOCKER_PHP) php $(PHPARGS) $(XPHPARGS) bin/php-openapi validate tests/spec/data/recursion.json
57+
$(DOCKER_PHP) php $(PHPARGS) $(XPHPARGS) bin/php-openapi validate tests/spec/data/recursion2.yaml
58+
$(DOCKER_PHP) php $(PHPARGS) $(XPHPARGS) bin/php-openapi validate tests/spec/data/empty-maps.json
59+
$(DOCKER_NODE) yarn run speccy lint tests/spec/data/reference/playlist.json
60+
$(DOCKER_NODE) yarn run speccy lint tests/spec/data/recursion.json
3461

3562
stan:
36-
php $(PHPARGS) vendor/bin/phpstan analyse -l 5 src
63+
$(DOCKER_PHP) php $(PHPARGS) vendor/bin/phpstan analyse -l 5 src
3764

3865
# copy openapi3 json schema
3966
schemas/openapi-v3.0.json: vendor/oai/openapi-specification-3.0/schemas/v3.0/schema.json

README.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ Supported OpenAPI versions:
1111

1212
[![Latest Stable Version](https://poser.pugx.org/cebe/php-openapi/v/stable)](https://packagist.org/packages/cebe/php-openapi)
1313
[![Total Downloads](https://poser.pugx.org/cebe/php-openapi/downloads)](https://packagist.org/packages/cebe/php-openapi)
14-
[![Build Status](https://github.com/cebe/php-openapi/workflows/PHP%20Composer/badge.svg)](https://github.com/cebe/php-openapi/actions)
15-
[![License](https://poser.pugx.org/cebe/php-openapi/license)](https://packagist.org/packages/cebe/php-openapi)
14+
[![Build Status](https://github.com/cebe/php-openapi/workflows/CI/badge.svg)](https://github.com/cebe/php-openapi/actions)
1615

1716

1817
## Install
@@ -200,9 +199,20 @@ references to structures in external files, we must provide the full context.
200199

201200
```php
202201
use cebe\openapi\Reader;
202+
use cebe\openapi\spec\OpenAPI;
203+
use cebe\openapi\ReferenceContext;
204+
205+
// there are two different modes for resolving references:
206+
// ALL: resolve all references, which will result in a large description with a lot of repetition
207+
// but no references (except if there are recursive references, these will stop at some level)
208+
$mode = ReferenceContext::RESOLVE_MODE_ALL;
209+
// INLINE: only references to external files are resolved, references to places in the current file
210+
// are still Reference objects.
211+
$mode = ReferenceContext::RESOLVE_MODE_INLINE;
212+
203213
// an absolute URL or file path is needed to allow resolving external references
204-
$openapi = Reader::readFromJsonFile('https://www.example.com/api/openapi.json');
205-
$openapi = Reader::readFromYamlFile('https://www.example.com/api/openapi.yaml');
214+
$openapi = Reader::readFromJsonFile('https://www.example.com/api/openapi.json', OpenAPI::class, $mode);
215+
$openapi = Reader::readFromYamlFile('https://www.example.com/api/openapi.yaml', OpenAPI::class, $mode);
206216
```
207217

208218
If data has been loaded in a different way you can manually resolve references like this by giving a context:
@@ -230,6 +240,15 @@ $errors = $openapi->getErrors();
230240
> but the list of errors given may not be complete. Also a passing validation does not necessarily indicate a completely
231241
> valid spec.
232242
243+
# Development
244+
245+
You may use the docker environment for local development:
246+
247+
docker-compose build
248+
make IN_DOCKER=1 install
249+
make IN_DOCKER=1 test
250+
...
251+
233252
# Support
234253

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

composer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"require": {
2121
"php": ">=7.1.0",
2222
"ext-json": "*",
23-
"symfony/yaml": "^3.4 | ^4.0 | ^5.0",
24-
"justinrainbow/json-schema": "^5.0"
23+
"symfony/yaml": "^3.4 || ^4 || ^5 || ^6",
24+
"justinrainbow/json-schema": "^5.2"
2525
},
2626
"require-dev": {
2727
"cebe/indent": "*",
@@ -35,14 +35,17 @@
3535
"nexmo/api-specification": "1.0.0",
3636
"phpstan/phpstan": "^0.12.0"
3737
},
38+
"conflict": {
39+
"symfony/yaml": "3.4.0 - 3.4.4 || 4.0.0 - 4.4.17 || 5.0.0 - 5.1.9 || 5.2.0"
40+
},
3841
"autoload": {
3942
"psr-4": {
4043
"cebe\\openapi\\": "src/"
4144
}
4245
},
4346
"extra": {
4447
"branch-alias": {
45-
"dev-master": "1.5.x-dev"
48+
"dev-master": "1.6.x-dev"
4649
}
4750
},
4851
"bin": [

docker-compose.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
version: "3"
2+
services:
3+
php:
4+
build:
5+
dockerfile: tests/docker/Dockerfile
6+
context: .
7+
volumes:
8+
- ./tests/tmp/.composer:/root/.composer:rw
9+
- .:/app
10+
environment:
11+
- TZ=UTC
12+
- TIMEZONE=UTC
13+
- IN_DOCKER=docker
14+
- PHP_XDEBUG_ENABLED=1
15+
- XDEBUG_CONFIG="remote_host=host.docker.internal"
16+
- PHP_IDE_CONFIG="serverName=Docker"
17+
tty: true
18+
node:
19+
image: node:12
20+
volumes:
21+
# - ./tests/tmp/.composer:/root/.composer:rw
22+
- .:/app

0 commit comments

Comments
 (0)