Skip to content

Commit bad2a24

Browse files
committed
fix(openapi): correct openapi errors
1 parent 344f91a commit bad2a24

6 files changed

Lines changed: 26 additions & 21 deletions

File tree

src/Doctrine/Common/Filter/BackedEnumFilterTrait.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ public function getDescription(string $resourceClass): array
6060
$isCollection = str_ends_with($filterParameterName, '[]');
6161

6262
$enumValues = array_map(static fn (\BackedEnum $case) => $case->value, $this->enumTypes[$property]::cases());
63+
$enumType = \is_int($enumValues[0] ?? null) ? 'integer' : 'string';
6364

6465
$schema = $isCollection
65-
? ['type' => 'array', 'items' => ['type' => 'string', 'enum' => $enumValues]]
66-
: ['type' => 'string', 'enum' => $enumValues];
66+
? ['type' => 'array', 'items' => ['type' => $enumType, 'enum' => $enumValues]]
67+
: ['type' => $enumType, 'enum' => $enumValues];
6768

6869
$description[$filterParameterName] = [
6970
'property' => $propertyName,

src/JsonApi/JsonSchema/SchemaFactory.php

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ private function buildDefinitionPropertiesSchema(string $key, string $className,
319319

320320
$refs[$this->getSchemaUriPrefix($schema->getVersion()).$definitionName] = '$ref';
321321
}
322-
$relatedDefinitions[$propertyName] = array_flip($refs);
322+
if (\count($refs) > 0) {
323+
$relatedDefinitions[$propertyName] = array_flip($refs);
324+
}
323325
if ($isOne) {
324326
$relationships[$propertyName]['properties']['data'] = [
325327
'oneOf' => [
@@ -354,19 +356,21 @@ private function buildDefinitionPropertiesSchema(string $key, string $className,
354356
'type' => 'object',
355357
'properties' => $relationships,
356358
];
357-
$included = [
358-
'included' => [
359-
'description' => 'Related resources requested via the "include" query parameter.',
360-
'type' => 'array',
361-
'items' => [
362-
'anyOf' => array_values($relatedDefinitions),
363-
],
364-
'readOnly' => true,
365-
'externalDocs' => [
366-
'url' => 'https://jsonapi.org/format/#fetching-includes',
359+
if (\count($relatedDefinitions) > 0) {
360+
$included = [
361+
'included' => [
362+
'description' => 'Related resources requested via the "include" query parameter.',
363+
'type' => 'array',
364+
'items' => [
365+
'anyOf' => array_values($relatedDefinitions),
366+
],
367+
'readOnly' => true,
368+
'externalDocs' => [
369+
'url' => 'https://jsonapi.org/format/#fetching-includes',
370+
],
367371
],
368-
],
369-
];
372+
];
373+
}
370374
}
371375

372376
return [

tests/Fixtures/TestBundle/ApiResource/DummyWebhook.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use ApiPlatform\OpenApi\Model\PathItem;
2222

2323
#[ApiResource(operations: [new Get(openapi: new Webhook(
24-
name: 'a',
24+
name: 'a/{id}',
2525
pathItem: new PathItem(
2626
get: new Operation(
2727
summary: 'Something else here',

tests/Fixtures/TestBundle/Entity/Issue6041/NumericValidated.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ class NumericValidated
3939
#[ORM\Column]
4040
public int $greaterThanMe;
4141

42-
#[Assert\GreaterThanOrEqual(value: '10.99')]
42+
#[Assert\GreaterThanOrEqual(value: 10.99)]
4343
#[ORM\Column]
4444
public float $greaterThanOrEqualToMe;
4545

4646
#[Assert\LessThan(value: 99)]
4747
#[ORM\Column]
4848
public int $lessThanMe;
4949

50-
#[Assert\LessThanOrEqual(value: '99.33')]
50+
#[Assert\LessThanOrEqual(value: 99.33)]
5151
#[ORM\Column]
5252
public float $lessThanOrEqualToMe;
5353

tests/Fixtures/TestBundle/Entity/Issue7135/Foo.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
shortName: 'FooPr7135',
2424
operations: [
2525
new Post(
26-
uriTemplate: '/pull-request-7135/foo/',
26+
uriTemplate: '/pull-request-7135/foo',
2727
),
2828
],
2929
normalizationContext: ['iri_only' => true],

tests/Functional/Issues/Issue7135Test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testValidPostRequestWithIriWhenIdentifierIsUuid(): void
4747
$this->recreateSchema(self::getResources());
4848
$bar = $this->loadBarFixture();
4949

50-
$response = self::createClient()->request('POST', '/pull-request-7135/foo/', [
50+
$response = self::createClient()->request('POST', '/pull-request-7135/foo', [
5151
'json' => [
5252
'bar' => 'pull-request-7135/bar/'.$bar->id,
5353
],
@@ -63,7 +63,7 @@ public function testInvalidPostRequestWithIriWhenIdentifierIsUuid(): void
6363
$this->markTestSkipped();
6464
}
6565

66-
$response = self::createClient()->request('POST', '/pull-request-7135/foo/', [
66+
$response = self::createClient()->request('POST', '/pull-request-7135/foo', [
6767
'json' => [
6868
'bar' => 'pull-request-7135/bar/invalid-uuid',
6969
],

0 commit comments

Comments
 (0)