Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
69c07ef
Added basic information about current OpenAPI version
cebe Oct 18, 2021
82b0db7
OpenAPI v3.1: Add schema and validation to CLI
cebe Oct 18, 2021
eb1108d
fix test paths
cebe Oct 18, 2021
4fcc155
Update README.md
cebe Oct 18, 2021
c4bba49
Add Testcases for OpenAPI 3.1
marcelthole Oct 20, 2021
2cb3b0d
Update php.yml
cebe Oct 28, 2021
551b05f
Merge pull request #129 from marcelthole/add-openapi31-examples
cebe Oct 31, 2021
0c10bea
Add support for WebHooks
WyriHaximus Jun 1, 2021
088af05
Merge pull request #115 from WyriHaximus-labs/webhooks
cebe Dec 21, 2021
c88cb31
Update pre-release openapi 3.1 schema to current (#140)
Xerkus Feb 9, 2022
684aac0
Merge branch 'master' into openapi-31
cebe Feb 9, 2022
fe0d912
Merge pull request #1 from DEVizzent/openapi-31
DEVizzent Jan 26, 2023
50100d3
Rename library to add it in packagist
DEVizzent Jan 26, 2023
c5a294e
Fix some links on README
DEVizzent Jan 26, 2023
ca5bed0
[openapi v3.1] PHP 8.2 deprecations
WyriHaximus Jan 13, 2023
aeedbc7
Merge pull request #3 from WyriHaximus-labs/DEVizzent-openapi-31-8.2-…
DEVizzent Mar 23, 2023
7e1563a
[openapi v3.1] Preserve property item keys
WyriHaximus Jan 17, 2023
7bd2bbf
NO-ISSUE Execute actions only for master and master's PRs
DEVizzent Jun 22, 2023
3f4f3d0
Revert "Merge pull request #3 from WyriHaximus-labs/DEVizzent-openapi…
DEVizzent Jun 22, 2023
72b4826
I-5 Remove uri format from server url
DEVizzent Jun 29, 2023
480b8b5
I-9 Check not empty openapi field before use it in preg_match
DEVizzent Jul 20, 2023
de3a406
I-13 Ignore yarn.lock, Makefile and docker-compose.yml in the exports
DEVizzent Oct 26, 2023
b20152d
Support Symfony 7
ttomdewit Nov 29, 2023
f102cbf
NO-ISSUE improve the local environment to use xdebug
DEVizzent Jun 22, 2023
89d71d0
I-9 Add definitions for testing from the removed library(nexmo/api-sp…
DEVizzent Jan 4, 2024
da687e3
I-9 Use the OpenApi definition from resourcet instead of the removed …
DEVizzent Jan 4, 2024
7bc2ebf
I-9 Ignore phpstorm data and xdebug logs
DEVizzent Jan 4, 2024
9821397
I-9 Remove the unreachable library
DEVizzent Jan 4, 2024
b5a5de8
Zip instead of cloning and removed reference to vanished repository
jongotlin Dec 9, 2023
fc3e73e
Add replacement to composer config
JarJak Apr 12, 2024
45db74e
Adding PHP8.3 and PHPUnit 11.4
Oct 25, 2024
f01933d
Adding branch to test if workflow runs
Oct 25, 2024
1a28e89
Reformulating exclusions for symfony-yaml 7
Oct 25, 2024
829fac4
Excluding versions of symfony-yaml for incompatibilities and adding c…
Oct 25, 2024
635ee69
Fixing condition tu run only unitary test with debug on php8.3
Oct 25, 2024
484034b
Fixng php8.3 to run properly with phpunit 11.4
Oct 25, 2024
a0fef54
Fixng php8.3 to run properly with phpunit 11.4
Oct 25, 2024
078e7ff
Merge remote-tracking branch 'origin/Adding_php83' into Adding_php83
Oct 25, 2024
6c80091
PHPUnit 11 and PHP8.3 all data providers have to be static
Oct 25, 2024
e9a332c
Excluding symfony-yaml 3.4 on php8.3 tests
Oct 25, 2024
9b7f746
Excluding symfony-yaml 3.4 on php8.3 tests
Oct 25, 2024
9ae960c
Merge branch 'onavascuez-Adding_php83'
DEVizzent Oct 30, 2024
7ac86b4
Support justinrainbow/json-schema version 6
Oct 30, 2024
9e20902
Update Schema to allow Numbers for 3.1 min and max
charjr Oct 31, 2024
4004029
Mark as nullable arguments with initial null value
acelaya Dec 1, 2024
44920bc
Add PHP 8.4 to php workflow
acelaya Dec 1, 2024
b4b2037
Summary and description support for references
hotrush Jan 10, 2025
42c86a2
Summary and description support for references
hotrush Jan 10, 2025
21051f6
Summary and description support for references
hotrush Jan 10, 2025
49c5a28
Summary and description support for references
hotrush Jan 10, 2025
2de3c45
Summary and description support for references
hotrush Jan 10, 2025
5cd2e0c
Summary and description support for references
hotrush Jan 10, 2025
82dbfcc
Summary and description support for references
hotrush Jan 10, 2025
26fd522
Summary and description support for references
hotrush Jan 10, 2025
b8486dc
Summary and description support for references
hotrush Jan 10, 2025
2612cf7
Add and sort gitattributes to decrease size of installed package
pieterocp Jan 10, 2025
af42b77
Readd needed folder schemas to the package
DEVizzent Jan 16, 2025
a13ec62
Add support for Symfony YAML v8 in GitHub Actions and composer.json
sfaujour Dec 1, 2025
3169923
FIX remove dependencies not needed
DEVizzent Jan 23, 2026
0060874
Fix the docker workflow
DEVizzent Jan 23, 2026
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
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/.github export-ignore
/tests export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.php_cs.dist export-ignore
docker-compose.yml export-ignore
Makefile export-ignore
phpunit.xml.dist export-ignore
phpunit11.xml.dist export-ignore
yarn.lock export-ignore
47 changes: 46 additions & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ jobs:
- "7.4"
- "8.0"
- "8.1"
- "8.3"
- "8.4"
dependencies:
- "lowest"
- "highest"
symfony-yaml: ['^3.4', '^4', '^5', '^6']
symfony-yaml: ['^3.4', '^4', '^5', '^6', '^7', '^8']
include:
- os: "windows-latest"
php: "8.0"
Expand All @@ -46,11 +48,45 @@ jobs:
symfony-yaml: '^6'
- php: '7.4'
symfony-yaml: '^6'
# symfony/yaml v7 does not run on PHP 7.*
- php: '7.1'
symfony-yaml: '^7'
- php: '7.2'
symfony-yaml: '^7'
- php: '7.3'
symfony-yaml: '^7'
- php: '7.4'
symfony-yaml: '^7'
# symfony/yaml v7 does not run on PHP 8.0 & 8.1
- php: '8.0'
symfony-yaml: '^7'
- php: '8.1'
symfony-yaml: '^7'
# symfony/yaml v8 does not run on PHP 7.*
- php: '7.1'
symfony-yaml: '^8'
- php: '7.2'
symfony-yaml: '^8'
- php: '7.3'
symfony-yaml: '^8'
- php: '7.4'
symfony-yaml: '^8'
# symfony/yaml v8 does not run on PHP < 8.4
- php: '8.0'
symfony-yaml: '^8'
- php: '8.1'
symfony-yaml: '^8'
- php: '8.3'
symfony-yaml: '^8'
# symfony/yaml v3.4 is not compatible with PHP 8.0 but has no upper-bound, so it installs on it
- php: '8.0'
symfony-yaml: '^3.4'
- php: '8.1'
symfony-yaml: '^3.4'
- php: '8.3'
symfony-yaml: '^3.4'
- php: '8.4'
symfony-yaml: '^3.4'

runs-on: ${{ matrix.os }}

Expand All @@ -71,6 +107,10 @@ jobs:
run: "composer require phpunit/phpunit '^9.5' --dev --no-interaction --ansi --no-install"
if: matrix.php == '8.1'

- name: Require newer phpunit/phpunit version
run: "composer require phpunit/phpunit '^11.4' --dev --no-interaction --ansi --no-install"
if: matrix.php >= '8.3'

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v2"
with:
Expand All @@ -81,6 +121,11 @@ jobs:

- name: PHPUnit tests
run: make test
if: matrix.php < '8.3'

- name: PHPUnit tests
run: make test-debug
if: matrix.php >= '8.3'

- name: Code coverage
run: make coverage
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@

/.php_cs.cache
/.phpunit.result.cache

/.idea
xdebug_remote.log
php-cs-fixer.phar
16 changes: 7 additions & 9 deletions Makefile
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ DOCKER_PHP=
DOCKER_NODE=
IN_DOCKER=0
ifeq ($(IN_DOCKER),1)
DOCKER_PHP=docker-compose run --rm php
DOCKER_NODE=docker-compose run --rm -w /app node
DOCKER_PHP=docker compose run --rm php
DOCKER_NODE=docker compose run --rm -w /app node
endif

all:
Expand Down Expand Up @@ -46,6 +46,11 @@ test: unit test-recursion.json test-recursion2.yaml test-recursion3_index.yaml t
unit:
$(DOCKER_PHP) php $(PHPARGS) $(XPHPARGS) vendor/bin/phpunit --verbose --colors=always $(TESTCASE)

test-debug: unit-debug test-recursion.json test-recursion2.yaml test-recursion3_index.yaml test-empty-maps.json

unit-debug:
$(DOCKER_PHP) php $(PHPARGS) $(XPHPARGS) vendor/bin/phpunit --debug --testdox --colors=always -c phpunit11.xml.dist $(TESTCASE)

# test specific JSON files in tests/spec/data/
# e.g. test-recursion will run validation on tests/spec/data/recursion.json
test-%: tests/spec/data/%
Expand All @@ -62,13 +67,6 @@ lint: install
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
cp $< $@

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

php-cs-fixer.phar:
wget -q https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.16.7/php-cs-fixer.phar && chmod +x php-cs-fixer.phar

Expand Down
81 changes: 17 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
## Atention
This is a fork of [cebe/php-openapi](https://github.com/cebe/php-openapi). I created it as library because the pull request
of the openapi3.1 was taking years and a lot of developers want to use it.

# 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.x Description files.

Supported OpenAPI versions:

It also provides a CLI tool for validating and converting OpenAPI 3.0.x Description files.
- 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)
[![Build Status](https://github.com/cebe/php-openapi/workflows/CI/badge.svg)](https://github.com/cebe/php-openapi/actions)
[![Latest Stable Version](https://poser.pugx.org/devizzent/cebe-php-openapi/v/stable)](https://packagist.org/packages/devizzent/cebe-php-openapi)
[![Total Downloads](https://poser.pugx.org/devizzent/cebe-php-openapi/downloads)](https://packagist.org/packages/devizzent/cebe-php-openapi)
[![Build Status](https://github.com/devizzent/cebe-php-openapi/workflows/CI/badge.svg)](https://github.com/devizzent/cebe-php-openapi/actions)


## Install

composer require cebe/php-openapi
composer require devizzent/cebe-php-openapi

## Requirements

Expand All @@ -22,11 +31,7 @@ It also provides a CLI tool for validating and converting OpenAPI 3.0.x Descript
This library provides a low level API for reading and writing OpenAPI files. It is used by higher level tools to
do awesome work:

- [cebe/yii2-openapi](https://github.com/cebe/yii2-openapi) Code Generator for REST API from OpenAPI 3 Descriptions, includes fake data generator.
- [cebe/yii2-app-api](https://github.com/cebe/yii2-app-api) Yii framework application template for developing API-first applications.
- [league/openapi-psr7-validator](https://github.com/thephpleague/openapi-psr7-validator) validates PSR-7 messages (HTTP request/response) against OpenAPI descriptions.
- [dsuurlant/response2schema](https://github.com/dsuurlant/response2schema) a quick and easy tool for generating OpenAPI schemas based on example data.
- ... ([add yours](https://github.com/cebe/php-openapi/edit/master/README.md#L24))
- ... ([add yours](https://github.com/devizzent/cebe-php-openapi/edit/master/README.md#L24))

## Usage

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,13 +249,3 @@ You may use the docker environment for local development:
make IN_DOCKER=1 test
...


# Support

**Need help with your API project?**

Professional support, consulting as well as software development services are available:

https://www.cebe.cc/en/contact

Development of this library is sponsored by [cebe.:cloud: "Your Professional Deployment Platform"](https://cebe.cloud).
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
Loading