From ae4ee60490a40aee157162cc510bb327200e1ac9 Mon Sep 17 00:00:00 2001 From: Bastien Lutz Date: Thu, 23 Nov 2023 23:19:07 +0100 Subject: [PATCH] fix(jsonschema): child entity property schema generation (#5988) Subrecource property schemes should be built with the same scheme type than their parent, otherwise this could lead to errors in the generated schemes. fixes #5988 --- src/JsonSchema/SchemaFactory.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/JsonSchema/SchemaFactory.php b/src/JsonSchema/SchemaFactory.php index 2874c9ac9f7..bc29cc991a7 100644 --- a/src/JsonSchema/SchemaFactory.php +++ b/src/JsonSchema/SchemaFactory.php @@ -139,13 +139,13 @@ public function buildSchema(string $className, string $format = 'json', string $ $definition['required'][] = $normalizedPropertyName; } - $this->buildPropertySchema($schema, $definitionName, $normalizedPropertyName, $propertyMetadata, $serializerContext, $format); + $this->buildPropertySchema($schema, $definitionName, $normalizedPropertyName, $propertyMetadata, $serializerContext, $format, $type); } return $schema; } - private function buildPropertySchema(Schema $schema, string $definitionName, string $normalizedPropertyName, ApiProperty $propertyMetadata, array $serializerContext, string $format): void + private function buildPropertySchema(Schema $schema, string $definitionName, string $normalizedPropertyName, ApiProperty $propertyMetadata, array $serializerContext, string $format, string $parentType): void { $version = $schema->getVersion(); if (Schema::VERSION_SWAGGER === $version || Schema::VERSION_OPENAPI === $version) { @@ -216,7 +216,7 @@ private function buildPropertySchema(Schema $schema, string $definitionName, str continue; } - $subSchema = $this->buildSchema($className, $format, Schema::TYPE_OUTPUT, null, $subSchema, $serializerContext + [self::FORCE_SUBSCHEMA => true], false); + $subSchema = $this->buildSchema($className, $format, $parentType, null, $subSchema, $serializerContext + [self::FORCE_SUBSCHEMA => true], false); if ($isCollection) { $propertySchema['items']['$ref'] = $subSchema['$ref']; unset($propertySchema['items']['type']);