Skip to content

Commit

Permalink
Fix some schema errors in scratch specs
Browse files Browse the repository at this point in the history
  • Loading branch information
DerManoMann committed Mar 22, 2024
1 parent 2b4e9f8 commit d64882f
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/Annotations/HeaderParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace OpenApi\Annotations;

use OpenApi\Annotations as OA;

/**
* A `@OA\Request` header parameter.
*
Expand Down
1 change: 1 addition & 0 deletions src/Annotations/JsonContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace OpenApi\Annotations;

use OpenApi\Generator;
use OpenApi\Annotations as OA;

/**
* Shorthand for a json response.
Expand Down
1 change: 1 addition & 0 deletions src/Annotations/Operation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/Annotations/PathParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace OpenApi\Annotations;

use OpenApi\Annotations as OA;

/**
* A `@OA\Request` path parameter.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Annotations/QueryParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

namespace OpenApi\Annotations;

use OpenApi\Annotations as OA;

/**
* A `@OA\Request` query parameter.
*
Expand Down
1 change: 1 addition & 0 deletions src/Annotations/XmlContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace OpenApi\Annotations;

use OpenApi\Generator;
use OpenApi\Annotations as OA;

/**
* Shorthand for a xml response.
Expand Down
8 changes: 6 additions & 2 deletions tests/Fixtures/Scratch/Examples.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
10 changes: 8 additions & 2 deletions tests/Fixtures/Scratch/Examples.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions tests/Fixtures/Scratch/UsingRefs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
Expand All @@ -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'),
Expand Down
9 changes: 6 additions & 3 deletions tests/Fixtures/Scratch/UsingRefs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ paths:
operationId: 6ecb3788642c6ba8ce8d99cbcd554dbe
parameters:
-
$ref: '#/components/parameters/itemName'
$ref: '#/components/parameters/item_name'
responses:
'200':
$ref: '#/components/responses/item'
Expand All @@ -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
2 changes: 1 addition & 1 deletion tests/ScratchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

Expand Down

0 comments on commit d64882f

Please sign in to comment.