-
Notifications
You must be signed in to change notification settings - Fork 937
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scratch test using custom attributes (#1423)
- Loading branch information
1 parent
33960e0
commit 0299edc
Showing
2 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php declare(strict_types=1); | ||
|
||
/** | ||
* @license Apache 2.0 | ||
*/ | ||
|
||
namespace OpenApi\Tests\Fixtures\Scratch; | ||
|
||
use OpenApi\Attributes as OAT; | ||
|
||
// ======== custom attributes ======================= | ||
|
||
#[\Attribute(\Attribute::TARGET_CLASS)] | ||
class CustomInfo extends OAT\Info | ||
{ | ||
} | ||
|
||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY)] | ||
class CustomSchema extends OAT\Schema | ||
{ | ||
} | ||
|
||
#[\Attribute(\Attribute::TARGET_PROPERTY | \Attribute::TARGET_PARAMETER)] | ||
class CustomProperty extends OAT\Property | ||
{ | ||
} | ||
|
||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY | \Attribute::TARGET_PARAMETER | \Attribute::TARGET_CLASS_CONSTANT | \Attribute::IS_REPEATABLE)] | ||
class CustomItem extends OAT\Property | ||
{ | ||
/** @param class-string $of */ | ||
public function __construct( | ||
string $of, | ||
?string $description = null | ||
) { | ||
parent::__construct( | ||
ref: $of, | ||
title: (new \ReflectionClass($of))->getShortName(), | ||
description: $description, | ||
); | ||
} | ||
} | ||
|
||
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY | \Attribute::TARGET_PARAMETER | \Attribute::TARGET_CLASS_CONSTANT | \Attribute::IS_REPEATABLE)] | ||
class CustomList extends OAT\Property | ||
{ | ||
/** @param class-string $of */ | ||
public function __construct(string $of, ?string $description = null) | ||
{ | ||
parent::__construct( | ||
title: (new \ReflectionClass($of))->getShortName(), | ||
description: $description, | ||
items: new OAT\Items(ref: $of) | ||
); | ||
} | ||
} | ||
|
||
#[\Attribute(\Attribute::TARGET_CLASS | \Attribute::TARGET_METHOD)] | ||
class CustomGet extends OAT\Get | ||
{ | ||
} | ||
|
||
// ======== application code ======================= | ||
|
||
#[CustomSchema()] | ||
class CAItemModel | ||
{ | ||
} | ||
|
||
#[CustomSchema()] | ||
class CAModel | ||
{ | ||
#[CustomProperty] | ||
public ?string $name; | ||
|
||
#[CustomItem(of: CAItemModel::class)] | ||
public readonly CAItemModel $item; | ||
|
||
#[CustomList(of: CAItemModel::class)] | ||
public readonly array $items; | ||
} | ||
|
||
#[CustomInfo( | ||
title: 'Extended Attributes Scratch', | ||
version: '1.0' | ||
)] | ||
#[CustomGet( | ||
path: '/api/endpoint', | ||
description: 'An endpoint', | ||
responses: [new OAT\Response(response: 200, description: 'OK')] | ||
)] | ||
class CAEndpoint | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: 'Extended Attributes Scratch' | ||
version: '1.0' | ||
paths: | ||
/api/endpoint: | ||
get: | ||
description: 'An endpoint' | ||
responses: | ||
'200': | ||
description: OK | ||
components: | ||
schemas: | ||
CAItemModel: { } | ||
CAModel: | ||
properties: | ||
name: | ||
type: string | ||
nullable: true | ||
item: | ||
$ref: '#/components/schemas/CAItemModel' | ||
items: | ||
title: CAItemModel | ||
type: array | ||
items: | ||
$ref: '#/components/schemas/CAItemModel' | ||
type: object |