Skip to content

Commit

Permalink
PHP 8.1 attributes (#982)
Browse files Browse the repository at this point in the history
* PHP 8.1 support
* Annotations can be used as PHP attributes
* New annotation `PathParameter` added
* Removal of deprecated static properties used to configure the underlying Doctrine annotations parser
* New annotation `Attachable` to allow to attach any data to annotations/attributes without affecting the generated spec
  • Loading branch information
DerManoMann authored Nov 28, 2021
1 parent 68c76ce commit dd5f1b7
Show file tree
Hide file tree
Showing 243 changed files with 5,169 additions and 1,723 deletions.
14 changes: 13 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ name: build

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test:
Expand All @@ -11,8 +15,11 @@ jobs:
fail-fast: true
matrix:
operating-system: [ ubuntu-latest ]
php: [ '7.2', '7.3', '7.4', '8.0' ]
php: [ '7.2', '7.3', '7.4', '8.0', '8.1' ]
dependencies: [ 'lowest', 'highest' ]
exclude:
- php: '8.1'
dependencies: 'lowest'

name: PHP ${{ matrix.php }} on ${{ matrix.operating-system }} with ${{ matrix.dependencies }} dependencies

Expand All @@ -33,3 +40,8 @@ jobs:

- name: PHPUnit Tests
run: bin/phpunit --configuration phpunit.xml.dist --coverage-text

- name: PHPUnit Legacy Tests
run: bin/phpunit --configuration phpunit.xml.dist --coverage-text
env:
PHPUNIT_ANALYSER: 'legacy'
4 changes: 4 additions & 0 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ name: code-style

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
php-cs:
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/security-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ name: security-checks

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
security-checker:
Expand Down
1 change: 1 addition & 0 deletions Examples/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Collection of code/annotation examples and their corresponding OpenAPI specs gen
using swagger-php annotations.

* openapi-spec: [source](openapi-spec) / [spec](openapi-spec/openapi-spec.yaml)
* openapi-spec-attributes: [source](openapi-spec-attributes) / [spec](openapi-spec-attributes/openapi-spec-attributes.yaml) - **requires PHP 8.1**
* petstore-3.0 (includes oauth2 auth flow): [source](petstore-3.0) / [spec](openapi-spec/petstore-3.0.yaml)

* **petstore.swagger.io**
Expand Down
26 changes: 20 additions & 6 deletions Examples/example-object/example-object.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace OpenApi\Examples\ExampleObject;

use OpenApi\Annotations as OA;

/**
Expand All @@ -8,6 +10,9 @@
* title="Example for response examples value"
* )
*/
class OpenApiSpec
{
}

/**
* @OA\Put(
Expand All @@ -28,6 +33,9 @@
* )
* )
*/
class UserUpdateEndpoint
{
}

/**
* @OA\Post(
Expand Down Expand Up @@ -70,18 +78,24 @@
* )
* )
*/
class UserAddEndpoint
{
}

/**
* @OA\Schema(
* schema="Result",
* title="Sample schema for using references",
* @OA\Property(
* property="status",
* type="string"
* ),
* property="status",
* type="string"
* ),
* @OA\Property(
* property="error",
* type="string"
* )
* property="error",
* type="string"
* )
* )
*/
class ResultSchema
{
}
35 changes: 21 additions & 14 deletions Examples/misc/misc-api.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
<?php

namespace OpenApi\Examples\Misc;

/**
* @OA\OpenApi(
* security={{"bearerAuth": {}}}
* )
*
* @OA\Info(
* title="Testing annotations from bugreports",
* version="1.0.0",
* description="NOTE:
This sentence is on a new line"
* )
*
* @OA\Components(
Expand All @@ -12,18 +22,7 @@
* ),
* @OA\Attachable()
* )
*/

/**
* @OA\Info(
* title="Testing annotations from bugreports",
* version="1.0.0",
* description="NOTE:
This sentence is on a new line"
* )
*/

/**
*
* @OA\Server(
* url="{schema}://host.dev",
* description="OpenApi parameters",
Expand All @@ -34,6 +33,9 @@
* )
* )
*/
class OpenApiSpec
{
}

/**
* An API endpoint.
Expand All @@ -48,7 +50,10 @@
* @OA\Response(response=200, description="Success")
* )
*/

class Endpoint
{
}

/**
* @OA\Response(
* response=200,
Expand All @@ -64,4 +69,6 @@
* )
* )
*/

class Response
{
}
2 changes: 1 addition & 1 deletion Examples/nesting/ActualModel.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace OpenApi\Tests\Fixtures\Processors\Nesting;
namespace OpenApi\Examples\Nesting;

/**
* @OA\Schema()
Expand Down
2 changes: 1 addition & 1 deletion Examples/nesting/AlmostModel.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace OpenApi\Tests\Fixtures\Processors\Nesting;
namespace OpenApi\Examples\Nesting;

/**
* @OA\Schema()
Expand Down
2 changes: 1 addition & 1 deletion Examples/nesting/ApiController.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace OpenApi\Tests\Fixtures\Processors\Nesting;
namespace OpenApi\Examples\Nesting;

/**
* An entity controller class.
Expand Down
2 changes: 1 addition & 1 deletion Examples/nesting/BaseModel.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace OpenApi\Tests\Fixtures\Processors\Nesting;
namespace OpenApi\Examples\Nesting;

/**
* @OA\Schema()
Expand Down
2 changes: 1 addition & 1 deletion Examples/nesting/IntermediateModel.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace OpenApi\Tests\Fixtures\Processors\Nesting;
namespace OpenApi\Examples\Nesting;

/**
* No schema!
Expand Down
2 changes: 1 addition & 1 deletion Examples/nesting/SoCloseModel.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php declare(strict_types=1);

namespace OpenApi\Tests\Fixtures\Processors\Nesting;
namespace OpenApi\Examples\Nesting;

/**
* No schema!
Expand Down
2 changes: 1 addition & 1 deletion Examples/nesting/nesting.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ paths:
get:
tags:
- api
operationId: 4db0bcd1e9358f78c662034e39c702b6
operationId: dd148eadcee53770e24b2350f932e3bd
parameters:
-
name: id
Expand Down
41 changes: 41 additions & 0 deletions Examples/openapi-spec-attributes/PullRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace OpenApi\Examples\OpenapiSpecAttributes;

use OpenApi\Annotations as OA;

/**
* @OA\Schema(schema="pullrequest")
*/
#[OA\Schema(schema: 'pullrequest')]
class PullRequest
{

/**
* @OA\Property()
* @var integer
*/
#[OA\Property(type: 'integer')]
public $id;

/**
* @OA\Property()
* @var string
*/
#[OA\Property(type: 'string')]
public $title;

/**
* @OA\Property()
* @var Repository
*/
#[OA\Property(ref: '#/components/schemas/repository')]
public $repository;

/**
* @OA\Property()
* @var User
*/
#[OA\Property(ref: '#/components/schemas/user')]
public $author;
}
Loading

0 comments on commit dd5f1b7

Please sign in to comment.