From 431e69eda43342752aa53a3cd11562f540973e57 Mon Sep 17 00:00:00 2001 From: Maxcastel Date: Tue, 21 Apr 2026 11:24:56 +0200 Subject: [PATCH] fix: fix openapi errors --- src/JsonApi/JsonSchema/SchemaFactory.php | 2 +- src/State/ApiResource/Error.php | 2 +- tests/Fixtures/TestBundle/Entity/Issue5793/BagOfTests.php | 2 +- tests/Functional/JsonSchema/JsonLdJsonSchemaTest.php | 1 + tests/Functional/JsonSchema/JsonSchemaTest.php | 1 + tests/Functional/OpenApiTest.php | 8 ++++++-- 6 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/JsonApi/JsonSchema/SchemaFactory.php b/src/JsonApi/JsonSchema/SchemaFactory.php index 17f3e172304..8e5b0667c59 100644 --- a/src/JsonApi/JsonSchema/SchemaFactory.php +++ b/src/JsonApi/JsonSchema/SchemaFactory.php @@ -147,7 +147,7 @@ public function buildSchema(string $className, string $format = 'jsonapi', strin 'items' => [ 'allOf' => [ ['$ref' => $prefix.$key], - ['type' => 'object', 'properties' => ['source' => ['type' => 'object'], 'status' => ['type' => 'string']]], + ['type' => 'object', 'properties' => ['source' => ['type' => 'object'], 'status' => ['type' => ['string', 'integer', 'null']]]], ], ], ], diff --git a/src/State/ApiResource/Error.php b/src/State/ApiResource/Error.php index ebee62fc084..365cdb7ffbf 100644 --- a/src/State/ApiResource/Error.php +++ b/src/State/ApiResource/Error.php @@ -127,7 +127,7 @@ public function __construct( identifier: true, writable: false, initializable: false, - schema: ['type' => ['number', 'null'], 'examples' => [404], 'default' => 400] + schema: ['type' => ['integer', 'null'], 'examples' => [404], 'default' => 400] )] private ?int $status, ?array $originalTrace = null, private ?string $instance = null, diff --git a/tests/Fixtures/TestBundle/Entity/Issue5793/BagOfTests.php b/tests/Fixtures/TestBundle/Entity/Issue5793/BagOfTests.php index 0a953efaa8e..ad660f0203d 100644 --- a/tests/Fixtures/TestBundle/Entity/Issue5793/BagOfTests.php +++ b/tests/Fixtures/TestBundle/Entity/Issue5793/BagOfTests.php @@ -37,7 +37,7 @@ class BagOfTests #[Groups(['read', 'write'])] // ignore "type" schema property to ensure "schema" is properly overridden // see JsonSchemaGenerateCommandTest::testArraySchemaWithReference - #[ApiProperty(schema: ['maxLength' => 255])] + #[ApiProperty(schema: ['type' => 'string', 'maxLength' => 255])] private ?string $description = null; #[ORM\OneToMany(mappedBy: 'bagOfTests', targetEntity: TestEntity::class)] diff --git a/tests/Functional/JsonSchema/JsonLdJsonSchemaTest.php b/tests/Functional/JsonSchema/JsonLdJsonSchemaTest.php index 488441c3d16..a8ea9f28ac7 100644 --- a/tests/Functional/JsonSchema/JsonLdJsonSchemaTest.php +++ b/tests/Functional/JsonSchema/JsonLdJsonSchemaTest.php @@ -65,6 +65,7 @@ public function testSubSchemaJsonLd(): void 'readOnly' => true, ]), 'description' => new \ArrayObject([ + 'type' => 'string', 'maxLength' => 255, ]), 'tests' => new \ArrayObject([ diff --git a/tests/Functional/JsonSchema/JsonSchemaTest.php b/tests/Functional/JsonSchema/JsonSchemaTest.php index 4cb366af8a8..da2da4d87bd 100644 --- a/tests/Functional/JsonSchema/JsonSchemaTest.php +++ b/tests/Functional/JsonSchema/JsonSchemaTest.php @@ -158,6 +158,7 @@ public function testArraySchemaWithReference(): void ])); $this->assertEquals($schema['definitions']['BagOfTests-write']['properties']['description'], new \ArrayObject([ + 'type' => 'string', 'maxLength' => 255, ])); diff --git a/tests/Functional/OpenApiTest.php b/tests/Functional/OpenApiTest.php index c15809667e2..1bfbe5f7496 100644 --- a/tests/Functional/OpenApiTest.php +++ b/tests/Functional/OpenApiTest.php @@ -161,7 +161,7 @@ public function testErrorsAreDocumented(): void ], 'status' => [ 'type' => [ - 'number', + 'integer', 'null', ], 'examples' => [ @@ -202,7 +202,11 @@ public function testErrorsAreDocumented(): void 'type' => 'object', ], 'status' => [ - 'type' => 'string', + 'type' => [ + 'string', + 'integer', + 'null', + ], ], ]], ]], $res['components']['schemas']['Error.jsonapi']['properties']['errors']['items']);