diff --git a/features/openapi/docs.feature b/features/openapi/docs.feature index 9fcae506c6c..1aa379c71b8 100644 --- a/features/openapi/docs.feature +++ b/features/openapi/docs.feature @@ -98,7 +98,6 @@ Feature: Documentation support And the "playMode" property for the OpenAPI class "VideoGame" should be equal to: """ { - "owl:maxCardinality": 1, "type": "string", "format": "iri-reference", "example": "https://example.com/" @@ -310,7 +309,6 @@ Feature: Documentation support And the "resourceRelated" property for the OpenAPI class "Resource" should be equal to: """ { - "owl:maxCardinality": 1, "readOnly": true, "anyOf": [ { @@ -389,7 +387,6 @@ Feature: Documentation support And the "data" property for the OpenAPI class "WrappedResponseEntity.CustomOutputEntityWrapperDto-read" should be equal to: """ { - "owl:maxCardinality": 1, "$ref": "#\/components\/schemas\/WrappedResponseEntity-read" } """ diff --git a/src/Hydra/Serializer/DocumentationNormalizer.php b/src/Hydra/Serializer/DocumentationNormalizer.php index a940a4c4411..f9e0c84f69c 100644 --- a/src/Hydra/Serializer/DocumentationNormalizer.php +++ b/src/Hydra/Serializer/DocumentationNormalizer.php @@ -386,6 +386,23 @@ private function getRange(ApiProperty $propertyMetadata): array|string|null return 1 === \count($types) ? $types[0] : $types; } + private function isSingleRelation(ApiProperty $propertyMetadata): bool + { + $builtInTypes = $propertyMetadata->getBuiltinTypes() ?? []; + + foreach ($builtInTypes as $type) { + $className = $type->getClassName(); + if (!$type->isCollection() + && null !== $className + && $this->resourceClassResolver->isResourceClass($className) + ) { + return true; + } + } + + return false; + } + /** * Builds the classes array. */ @@ -509,6 +526,10 @@ private function getProperty(ApiProperty $propertyMetadata, string $propertyName $property['owl:deprecated'] = true; } + if ($this->isSingleRelation($propertyMetadata)) { + $property['owl:maxCardinality'] = true; + } + return $property; } diff --git a/src/JsonSchema/Metadata/Property/Factory/SchemaPropertyMetadataFactory.php b/src/JsonSchema/Metadata/Property/Factory/SchemaPropertyMetadataFactory.php index f906f25ea3d..f2713a51866 100644 --- a/src/JsonSchema/Metadata/Property/Factory/SchemaPropertyMetadataFactory.php +++ b/src/JsonSchema/Metadata/Property/Factory/SchemaPropertyMetadataFactory.php @@ -125,14 +125,6 @@ public function create(string $resourceClass, string $property, array $options = $className = $valueType->getClassName(); } - if (!\array_key_exists('owl:maxCardinality', $propertySchema) - && !$isCollection - && null !== $className - && $this->resourceClassResolver->isResourceClass($className) - ) { - $propertySchema['owl:maxCardinality'] = 1; - } - if ($isCollection && null !== $propertyMetadata->getUriTemplate()) { $keyType = null; $isCollection = false; diff --git a/src/OpenApi/Serializer/LegacyOpenApiNormalizer.php b/src/OpenApi/Serializer/LegacyOpenApiNormalizer.php index a7d7381fc12..16a6b730e0e 100644 --- a/src/OpenApi/Serializer/LegacyOpenApiNormalizer.php +++ b/src/OpenApi/Serializer/LegacyOpenApiNormalizer.php @@ -45,7 +45,6 @@ public function normalize(mixed $object, string $format = null, array $context = } unset($schemas[$name]['properties'][$property]['type']); } - unset($schemas[$name]['properties'][$property]['owl:maxCardinality']); } } diff --git a/tests/JsonSchema/Command/JsonSchemaGenerateCommandTest.php b/tests/JsonSchema/Command/JsonSchemaGenerateCommandTest.php index 27475fe839e..8800fd5265e 100644 --- a/tests/JsonSchema/Command/JsonSchemaGenerateCommandTest.php +++ b/tests/JsonSchema/Command/JsonSchemaGenerateCommandTest.php @@ -120,7 +120,6 @@ public function testArraySchemaWithReference(): void ]); $this->assertEquals($json['definitions']['BagOfTests.jsonld-write']['properties']['type'], [ - 'owl:maxCardinality' => 1, '$ref' => '#/definitions/TestEntity.jsonld-write', ]); }