From 0299edc47eb4813a2c598a0348eaf205704adc92 Mon Sep 17 00:00:00 2001 From: Martin Rademacher Date: Wed, 8 Mar 2023 15:27:27 +1300 Subject: [PATCH] Add scratch test using custom attributes (#1423) --- tests/Fixtures/Scratch/CustomAttributes.php | 94 ++++++++++++++++++++ tests/Fixtures/Scratch/CustomAttributes.yaml | 27 ++++++ 2 files changed, 121 insertions(+) create mode 100644 tests/Fixtures/Scratch/CustomAttributes.php create mode 100644 tests/Fixtures/Scratch/CustomAttributes.yaml diff --git a/tests/Fixtures/Scratch/CustomAttributes.php b/tests/Fixtures/Scratch/CustomAttributes.php new file mode 100644 index 00000000..c913c65f --- /dev/null +++ b/tests/Fixtures/Scratch/CustomAttributes.php @@ -0,0 +1,94 @@ +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 +{ +} diff --git a/tests/Fixtures/Scratch/CustomAttributes.yaml b/tests/Fixtures/Scratch/CustomAttributes.yaml new file mode 100644 index 00000000..4922eb54 --- /dev/null +++ b/tests/Fixtures/Scratch/CustomAttributes.yaml @@ -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