Skip to content

Commit

Permalink
fix(jsonschema): child entity property schema generation (#5988) (#5989)
Browse files Browse the repository at this point in the history
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

Co-authored-by: Bastien Lutz <bastien.lutz@in2code.de>
  • Loading branch information
Fr13nzzz and BastiLu committed Nov 24, 2023
1 parent 1b42894 commit ce297e6
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/JsonSchema/SchemaFactory.php
Expand Up @@ -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) {
Expand Down Expand Up @@ -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']);
Expand Down

0 comments on commit ce297e6

Please sign in to comment.