Skip to content

Commit

Permalink
Merge branch 'zircote:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
momala454 committed Aug 31, 2023
2 parents a3fd643 + e1062da commit 1e2fdcd
Show file tree
Hide file tree
Showing 9 changed files with 134 additions and 14 deletions.
3 changes: 2 additions & 1 deletion Examples/using-links-php81/PullRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
class PullRequest
{
public function __construct(
#[OAT\Property()] public State $state
#[OAT\Property()]
public State $state
) {
}

Expand Down
12 changes: 8 additions & 4 deletions Examples/using-links-php81/RepositoriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,14 @@ public function getRepository()
]
#[OAT\Link(link: 'RepositoryPullRequests', operationId: 'getPullRequestsByRepository', parameters: ['username' => '$response.body#/owner/username', 'slug' => '$response.body#/slug'])]
public function getPullRequestsByRepository(
#[OAT\PathParameter()] string $username,
#[OAT\PathParameter()] string $slug,
#[OAT\PathParameter()] State $state,
#[OAT\QueryParameter()] ?string $label
#[OAT\PathParameter()]
string $username,
#[OAT\PathParameter()]
string $slug,
#[OAT\PathParameter()]
State $state,
#[OAT\QueryParameter()]
?string $label
) {
}

Expand Down
2 changes: 1 addition & 1 deletion src/Analysers/TokenScanner.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected function scanTokens(array $tokens): array
while (false !== ($token = $this->nextToken($tokens))) {
// named arguments
$nextToken = $this->nextToken($tokens);
if ($nextToken === ':' || $nextToken === false) {
if (($token !== '}' && $nextToken === ':') || $nextToken === false) {
continue;
}
do {
Expand Down
2 changes: 1 addition & 1 deletion src/Analysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ public function unmerged(): Analysis
* Split the annotation into two analysis.
* One with annotations that are merged and one with annotations that are not merged.
*
* @return object {merged: Analysis, unmerged: Analysis}
* @return \stdClass {merged: Analysis, unmerged: Analysis}
*/
public function split()
{
Expand Down
8 changes: 6 additions & 2 deletions src/Annotations/AbstractAnnotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,12 @@ public function jsonSerialize()
if ($this->_context->version === OpenApi::VERSION_3_1_0) {
if (isset($data->nullable)) {
if (true === $data->nullable) {
$data->type = (array) $data->type;
$data->type[] = 'null';
if (isset($data->oneOf)) {
$data->oneOf[] = ['type' => 'null'];
} else {
$data->type = (array) $data->type;
$data->type[] = 'null';
}
}
unset($data->nullable);
}
Expand Down
19 changes: 19 additions & 0 deletions tests/Analysers/TokenScannerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,25 @@ public function scanCases(): iterable
],
];

yield 'CurlyBrace' => [
'PHP/MultipleFunctions.php',
[
'OpenApi\Tests\Fixtures\PHP\MultipleFunctions' => [
'uses' => [
'OA' => 'OpenApi\Annotations',
],
'interfaces' => [],
'traits' => [],
'enums' => [],
'methods' => [
'first',
'second',
],
'properties' => [],
],
],
];

yield 'namespaces1' => [
'PHP/namespaces1.php',
[
Expand Down
15 changes: 10 additions & 5 deletions tests/Fixtures/Apis/Attributes/basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,14 @@ class Product implements ProductInterface
public $id;

public function __construct(
#[OAT\Property()] public int $quantity,
#[OAT\Property(default: null, example: null)] public ?string $brand,
#[OAT\Property()] public Colour $colour,
#[OAT\Property(type: 'string')] public \DateTimeInterface $releasedAt,
#[OAT\Property()]
public int $quantity,
#[OAT\Property(default: null, example: null)]
public ?string $brand,
#[OAT\Property()]
public Colour $colour,
#[OAT\Property(type: 'string')]
public \DateTimeInterface $releasedAt,
) {
}
}
Expand All @@ -118,7 +122,8 @@ class ProductController
#[OAT\Response(response: 401, description: 'oops')]
#[OAF\CustomAttachable(value: 'operation')]
public function getProduct(
#[OAT\PathParameter] ?int $product_id
#[OAT\PathParameter]
?int $product_id
) {
}

Expand Down
31 changes: 31 additions & 0 deletions tests/Fixtures/PHP/MultipleFunctions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php declare(strict_types=1);

/**
* @license Apache 2.0
*/

namespace OpenApi\Tests\Fixtures\PHP;

use OpenApi\Annotations as OA;

/**
* @OA\Info(title="Test", version="1.0")
*/
class MultipleFunctions
{
public function first()
{
$category = new \stdClass();
$prefix = '1';
$category->name = '1';

return isset($category->{'name' . $prefix}) && $category->{'name' . $prefix}
? $category->{'name' . $prefix}
: $category->name;
}

public function second()
{

}
}
56 changes: 56 additions & 0 deletions tests/Fixtures/Scratch/Nullable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php declare(strict_types=1);

/**
* @license Apache 2.0
*/

namespace OpenApi\Tests\Fixtures\Scratch;

use OpenApi\Attributes as OAT;

#[OAT\OpenApi(openapi: '3.1.0')]
#[OAT\Info(title: 'Nullable', version: '1.0')]
class Api
{
}

#[OAT\Schema(
type: 'string',
format: 'rfc3339-timestamp',
externalDocs: new OAT\ExternalDocumentation(
description: '**RFC3339** IETF',
url: 'https://tools.ietf.org/html/rfc3339'
),
example: '2023-08-02T07:06:46+03:30'
)]
class MyDateTime
{
}

#[OAT\Schema]
class Nullable
{
#[OAT\Property]
public ?string $firstname;

#[OAT\Property(nullable: true)]
public ?string $lastname;

#[OAT\Property]
public ?MyDateTime $birthdate;

#[OAT\Property(nullable: true)]
public MyDateTime $otherdate;

#[OAT\Property]
public MyDateTime|null $anotherdate;
}

#[OAT\Get(
path: '/api/endpoint',
description: 'An endpoint',
responses: [new OAT\Response(response: 200, description: 'OK')]
)]
class NullableEndpoint
{
}

0 comments on commit 1e2fdcd

Please sign in to comment.