From d64882faf35419c136b59c60b17d47f8bc935d65 Mon Sep 17 00:00:00 2001 From: DerManoMann Date: Fri, 22 Mar 2024 14:18:12 +1300 Subject: [PATCH] Fix some schema errors in scratch specs --- src/Annotations/HeaderParameter.php | 2 ++ src/Annotations/JsonContent.php | 1 + src/Annotations/Operation.php | 1 + src/Annotations/PathParameter.php | 2 ++ src/Annotations/QueryParameter.php | 2 ++ src/Annotations/XmlContent.php | 1 + tests/Fixtures/Scratch/Examples.php | 8 ++++++-- tests/Fixtures/Scratch/Examples.yaml | 10 ++++++++-- tests/Fixtures/Scratch/UsingRefs.php | 4 ++-- tests/Fixtures/Scratch/UsingRefs.yaml | 9 ++++++--- tests/ScratchTest.php | 2 +- 11 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/Annotations/HeaderParameter.php b/src/Annotations/HeaderParameter.php index 439a2c018..6b946eabf 100644 --- a/src/Annotations/HeaderParameter.php +++ b/src/Annotations/HeaderParameter.php @@ -6,6 +6,8 @@ namespace OpenApi\Annotations; +use OpenApi\Annotations as OA; + /** * A `@OA\Request` header parameter. * diff --git a/src/Annotations/JsonContent.php b/src/Annotations/JsonContent.php index 357db5ce6..531e4ff78 100644 --- a/src/Annotations/JsonContent.php +++ b/src/Annotations/JsonContent.php @@ -7,6 +7,7 @@ namespace OpenApi\Annotations; use OpenApi\Generator; +use OpenApi\Annotations as OA; /** * Shorthand for a json response. diff --git a/src/Annotations/Operation.php b/src/Annotations/Operation.php index e4d1e9acd..bc089dc17 100644 --- a/src/Annotations/Operation.php +++ b/src/Annotations/Operation.php @@ -7,6 +7,7 @@ namespace OpenApi\Annotations; use OpenApi\Generator; +use OpenApi\Annotations as OA; /** * Base class for `@OA\Get`, `@OA\Post`, `@OA\Put`, etc. diff --git a/src/Annotations/PathParameter.php b/src/Annotations/PathParameter.php index 4e3d42c8b..e8d157373 100644 --- a/src/Annotations/PathParameter.php +++ b/src/Annotations/PathParameter.php @@ -6,6 +6,8 @@ namespace OpenApi\Annotations; +use OpenApi\Annotations as OA; + /** * A `@OA\Request` path parameter. * diff --git a/src/Annotations/QueryParameter.php b/src/Annotations/QueryParameter.php index 6ee3e47f8..311341a07 100644 --- a/src/Annotations/QueryParameter.php +++ b/src/Annotations/QueryParameter.php @@ -6,6 +6,8 @@ namespace OpenApi\Annotations; +use OpenApi\Annotations as OA; + /** * A `@OA\Request` query parameter. * diff --git a/src/Annotations/XmlContent.php b/src/Annotations/XmlContent.php index 59f765117..3c81bc30a 100644 --- a/src/Annotations/XmlContent.php +++ b/src/Annotations/XmlContent.php @@ -7,6 +7,7 @@ namespace OpenApi\Annotations; use OpenApi\Generator; +use OpenApi\Annotations as OA; /** * Shorthand for a xml response. diff --git a/tests/Fixtures/Scratch/Examples.php b/tests/Fixtures/Scratch/Examples.php index f459c71f2..36f040de4 100644 --- a/tests/Fixtures/Scratch/Examples.php +++ b/tests/Fixtures/Scratch/Examples.php @@ -19,12 +19,16 @@ class ExampleSchema #[OAT\Get( path: '/endpoint/{name}/{other}', parameters: [ - new OAT\QueryParameter( + new OAT\PathParameter( name: 'name', + required: true, + schema: new OAT\Schema(type: 'string'), example: 'Fritz' ), - new OAT\QueryParameter( + new OAT\PathParameter( name: 'other', + required: true, + schema: new OAT\Schema(type: 'string'), examples: [ new OAT\Examples( example: 'o1', diff --git a/tests/Fixtures/Scratch/Examples.yaml b/tests/Fixtures/Scratch/Examples.yaml index 1d6205189..8e2208115 100644 --- a/tests/Fixtures/Scratch/Examples.yaml +++ b/tests/Fixtures/Scratch/Examples.yaml @@ -9,11 +9,17 @@ paths: parameters: - name: name - in: query + in: path + required: true + schema: + type: string example: Fritz - name: other - in: query + in: path + required: true + schema: + type: string examples: o1: summary: 'other example 1' diff --git a/tests/Fixtures/Scratch/UsingRefs.php b/tests/Fixtures/Scratch/UsingRefs.php index 33093a38b..9e6d9a6cc 100644 --- a/tests/Fixtures/Scratch/UsingRefs.php +++ b/tests/Fixtures/Scratch/UsingRefs.php @@ -8,7 +8,7 @@ use OpenApi\Attributes as OAT; -#[OAT\PathParameter(name: 'itemName', description: 'The item name')] +#[OAT\PathParameter(name: 'item_name', description: 'The item name', required: true, schema: new OAT\Schema(type: 'string'))] class UsingRefsParameter { } @@ -22,7 +22,7 @@ class UsingRefsResponse #[OAT\Get( path: '/item/{item_name}', parameters: [ - new OAT\Parameter(ref: '#/components/parameters/itemName'), + new OAT\Parameter(ref: '#/components/parameters/item_name'), ], responses: [ new OAT\Response(response: 200, ref: '#/components/responses/item'), diff --git a/tests/Fixtures/Scratch/UsingRefs.yaml b/tests/Fixtures/Scratch/UsingRefs.yaml index 71bbeb877..99cd107a3 100644 --- a/tests/Fixtures/Scratch/UsingRefs.yaml +++ b/tests/Fixtures/Scratch/UsingRefs.yaml @@ -8,7 +8,7 @@ paths: operationId: 6ecb3788642c6ba8ce8d99cbcd554dbe parameters: - - $ref: '#/components/parameters/itemName' + $ref: '#/components/parameters/item_name' responses: '200': $ref: '#/components/responses/item' @@ -17,7 +17,10 @@ components: item: description: 'Item response' parameters: - itemName: - name: itemName + item_name: + name: item_name in: path description: 'The item name' + required: true + schema: + type: string diff --git a/tests/ScratchTest.php b/tests/ScratchTest.php index af9cb415f..916a44905 100644 --- a/tests/ScratchTest.php +++ b/tests/ScratchTest.php @@ -45,7 +45,7 @@ public function testScratch(string $scratch, string $spec, array $expectedLog): $openapi = (new Generator($this->getTrackingLogger())) ->generate([$scratch]); - if (true || !file_exists($spec)) { + if (!file_exists($spec)) { file_put_contents($spec, $openapi->toYaml()); }