Skip to content
Merged
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
6 changes: 1 addition & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fail-fast: true
matrix:
operating-system: [ ubuntu-latest ]
php: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ]
php: [ '8.2', '8.3', '8.4', '8.5' ]
dependencies: [ 'lowest', 'highest' ]

name: PHP ${{ matrix.php }} on ${{ matrix.operating-system }} with ${{ matrix.dependencies }} dependencies
Expand All @@ -38,9 +38,5 @@ jobs:
dependency-versions: ${{ matrix.dependencies }}
composer-options: "${{ matrix.composer-options }}"

- name: Require type-info-extras
if: ${{ matrix.php >= '8.2' }}
run: composer require radebatz/type-info-extras -W

- name: PHPUnit Tests
run: bin/phpunit --configuration phpunit.xml.dist --coverage-text
2 changes: 1 addition & 1 deletion .github/workflows/security-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
fail-fast: true
matrix:
operating-system: [ ubuntu-latest ]
php: [ '7.4', '8.0', '8.1', '8.2', '8.3', '8.4', '8.5' ]
php: [ '8.2', '8.3', '8.4', '8.5' ]
dependencies: [ 'highest' ]

name: PHP ${{ matrix.php }} on ${{ matrix.operating-system }} with ${{ matrix.dependencies }} dependencies
Expand Down
4 changes: 3 additions & 1 deletion .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
'trim_array_spaces' => true,
'single_space_around_construct' => true,
'single_line_comment_spacing' => true,
'fully_qualified_strict_types' => true,
'fully_qualified_strict_types' => ['import_symbols' => true, 'leading_backslash_in_global_namespace' => true],
'global_namespace_import' => ['import_classes' => false, 'import_constants' => null, 'import_functions' => null],

'nullable_type_declaration_for_default_null_value' => true,
Expand All @@ -89,5 +89,7 @@
'phpdoc_no_empty_return' => true,
'phpdoc_no_alias_tag' => true,
'phpdoc_param_order' => true,

'php_unit_attributes' => true,
])
->setFinder($finder);
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Programmatically, the method `Generator::setVersion()` can be used to change the

## Requirements

`swagger-php` requires at least PHP 7.4 for annotations and PHP 8.1 for using attributes.
`swagger-php` requires at least PHP 8.2.

## Installation (with [Composer](https://getcomposer.org))

Expand Down Expand Up @@ -75,6 +75,9 @@ composer require doctrine/annotations
Add annotations to your php files.

```php

use OpenApi\Annotations as OA;

/**
* @OA\Info(title="My First API", version="0.1")
*/
Expand All @@ -96,7 +99,7 @@ Generate always-up-to-date documentation.
```php
<?php
require("vendor/autoload.php");
$openapi = \OpenApi\Generator::scan(['/path/to/project']);
$openapi = (new \OpenApi\Generator->generate(['/path/to/project']);
header('Content-Type: application/x-yaml');
echo $openapi->toYaml();
```
Expand Down
4 changes: 2 additions & 2 deletions bin/openapi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use OpenApi\Analysers\DocBlockAnnotationFactory;
use OpenApi\Analysers\ReflectionAnalyser;
use OpenApi\Annotations\OpenApi;
use OpenApi\Generator;
use OpenApi\Util;
use OpenApi\SourceFinder;
use OpenApi\Loggers\ConsoleLogger;

if (class_exists(Generator::class) === false) {
Expand Down Expand Up @@ -224,7 +224,7 @@ $openapi = $generator
->setVersion($options['version'])
->setConfig($options['config'])
->setAnalyser($analyser)
->generate(Util::finder($paths, $exclude, $pattern));
->generate(new SourceFinder($paths, $exclude, $pattern));

if ($options['output'] === false) {
if (strtolower($options['format']) === 'json') {
Expand Down
16 changes: 7 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@
"minimum-stability": "stable",
"extra": {
"branch-alias": {
"dev-master": "5.x-dev"
"dev-master": "6.x-dev"
}
},
"require": {
"php": ">=7.4",
"php": ">=8.2",
"ext-json": "*",
"nikic/php-parser": "^4.19 || ^5.0",
"phpstan/phpdoc-parser": "^2.0",
"psr/log": "^1.1 || ^2.0 || ^3.0",
"radebatz/type-info-extras": "^1.0.2",
"symfony/deprecation-contracts": "^2 || ^3",
"symfony/finder": "^5.0 || ^6.0 || ^7.0",
"symfony/yaml": "^5.4 || ^6.0 || ^7.0"
Expand All @@ -73,23 +74,21 @@
"doctrine/annotations": "^2.0",
"friendsofphp/php-cs-fixer": "^3.62.0",
"phpstan/phpstan": "^1.6 || ^2.0",
"phpunit/phpunit": "^9.0",
"rector/rector": "^1.0 || ^2.0",
"vimeo/psalm": "^4.30 || ^5.0"
"phpunit/phpunit": "^10.5",
"rector/rector": "^1.0 || ^2.0"
},
"conflict": {
"symfony/process": ">=6, <6.4.14"
},
"suggest": {
"radebatz/type-info-extras": "^1.0.2",
"doctrine/annotations": "^2.0"
},
"scripts-descriptions": {
"cs": "Fix all codestyle issues",
"rector": "Automatic refactoring",
"lint": "Test codestyle",
"test": "Run all PHP, codestyle and rector tests",
"analyse": "Run static analysis (phpstan/psalm)",
"analyse": "Run static analysis (phpstan)",
"spectral-examples": "Run spectral lint over all .yaml files in the docs/examples folder",
"spectral-scratch": "Run spectral lint over all .yaml files in the tests/Fixtures/Scratch folder",
"spectral": "Run all spectral tests",
Expand All @@ -112,8 +111,7 @@
"@lint"
],
"analyse": [
"export XDEBUG_MODE=off && phpstan analyse --memory-limit=2G",
"export XDEBUG_MODE=off && psalm --threads=1"
"export XDEBUG_MODE=off && phpstan analyse --memory-limit=3G"
],
"spectral-examples": "for ff in `find docs/examples -name '*.yaml'`; do npm run spectral lint $ff; done",
"spectral-scratch": "for ff in `find tests/Fixtures/Scratch -name '*.yaml'`; do npm run spectral lint $ff; done",
Expand Down
1 change: 1 addition & 0 deletions docs/.vitepress/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ function getGuideSidebar() {
{
text: 'Upgrading',
items: [
{ text: 'Migration from 5.x to 6.x', link: '/guide/migrating-to-v6' },
{ text: 'Migration from 4.x to 5.x', link: '/guide/migrating-to-v5' },
{ text: 'Migration from 3.x to 4.x', link: '/guide/migrating-to-v4' },
{ text: 'Migration from 2.x to 3.x', link: '/guide/migrating-to-v3' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ class SchemaQueryParameter

public function __invoke(Analysis $analysis): void
{
/** @var Operation[] $operations */
$operations = $analysis->getAnnotationsOfType(Operation::class);

foreach ($operations as $operation) {
Expand All @@ -34,7 +33,7 @@ public function __invoke(Analysis $analysis): void
throw new \InvalidArgumentException('Value of `x.' . self::REF . '` must be a string');
}

$schema = $analysis->getSchemaForSource($operation->x[self::REF]);
$schema = $analysis->getAnnotationForSource($operation->x[self::REF]);
if (!$schema instanceof Schema) {
throw new \InvalidArgumentException('Value of `x.' . self::REF . "` contains reference to unknown schema: `{$operation->x[self::REF]}`");
}
Expand Down
1 change: 0 additions & 1 deletion docs/examples/specs/api/annotations/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public function getProduct(?int $product_id)
* @OA\MediaType(
* mediaType="application/json",
* @OA\Schema(
* type="array",
* @OA\Items(ref="#/components/schemas/Product")
* )
* )
Expand Down
1 change: 0 additions & 1 deletion docs/examples/specs/api/attributes/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public function getProduct(
content: [new OAT\MediaType(
mediaType: 'application/json',
schema: new OAT\Schema(
type: 'array',
items: new OAT\Items(type: Product::class)
)
)]
Expand Down
1 change: 0 additions & 1 deletion docs/examples/specs/api/mixed/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public function getProduct(?int $product_id)
* description="New product",
* required=true,
* @OA\JsonContent(
* type="array",
* @OA\Items(ref="#/components/schemas/Product")
* )
* )
Expand Down
4 changes: 2 additions & 2 deletions docs/guide/generating-openapi-documents.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ In its simplest form this may look something like

```php
<?php
require("vendor/autoload.php");
require('vendor/autoload.php');

$openapi = \OpenApi\Generator::scan(['/path/to/project']);
$openapi = (new \OpenApi\Generator)->generate(['/path/to/project']);

header('Content-Type: application/x-yaml');
echo $openapi->toYaml();
Expand Down
3 changes: 1 addition & 2 deletions docs/guide/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ either adding [`Annotations`](using-annotations.md) or [`Attributes`](using-attr
:::

::: warning Requirements
Using `swagger-php` requires a minimum of **PHP&nbsp;7.4** for using annotations and
at least **PHP&nbsp;8.1** to use attributes.
Using `swagger-php` requires a minimum of **PHP&nbsp;8.2**.
:::
34 changes: 34 additions & 0 deletions docs/guide/migrating-to-v6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Migrating to v6

## Overview

`v6` is mostly a cleanup release, with updated dependencies. The main changes are:

* The minimum required PHP version is now 8.2
* `radebatz/type-info-extras` is now a required dependency
* `TypeInfoTypeResolver` now properly handles composite types (unions and intersections)
* Some deprecations have been removed (see below)
* The `MediaType::encoding` property now only accepts `Encoding` objects (BC break)

For most installations upgrading should not require any changes.

## Type resolvers
With `radebatz/type-info-extras` now being a required dependency, the `TypeInfoTypeResolver` is not the de-facto default
resolver.

The `LegacyTypeResolver` can still be used as a drop-in replacement, but is now marked `deprecated` and will be removed
in v7.

## Removed deprecated elements
### Methods `\Openapi\Generator::getProcessors()` and `\Openapi\Generator::setProcessors()`
Use `getProcessorPipeline()` and `setProcessorPipeline(new Pipeline(...))` methods instead

### Static method `\Openapi\Generator::scan()`
Main entry point into the `Generator` is now the **non-static** `generate()` method:
```php
(new Generator())->generate(/* ... */);
```

### `Utils` helper
Most methods in the class were internal to start with and the `Util::finder()` factory methods is now replaced with
the new `SourceFinder` class.
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ features:

Add `swagger-php` attributes (or legacy annotations) to your source code.

⚠️ `doctrine/annotations` is going to be deprecated in the future, so wherever
⚠️ The `doctrine/annotations` library used to parse annotation is going to be deprecated, so wherever
possible attributes should be used.

<codeblock id="minimal">
Expand Down
Loading