Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/JsonSchema/SchemaFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

namespace ApiPlatform\JsonSchema;

use ApiPlatform\JsonSchema\Metadata\Property\Factory\SchemaPropertyMetadataFactory;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\CollectionOperationInterface;
use ApiPlatform\Metadata\Exception\OperationNotFoundException;
Expand Down Expand Up @@ -158,6 +159,15 @@ private function buildPropertySchema(Schema $schema, string $definitionName, str
$additionalPropertySchema ?? []
);

$extraProperties = $propertyMetadata->getExtraProperties() ?? [];
// see AttributePropertyMetadataFactory
if (true === ($extraProperties[SchemaPropertyMetadataFactory::JSON_SCHEMA_USER_DEFINED] ?? false)) {
// schema seems to have been declared by the user: do not override nor complete user value
$schema->getDefinitions()[$definitionName]['properties'][$normalizedPropertyName] = new \ArrayObject($propertySchema);

return;
}

$types = $propertyMetadata->getBuiltinTypes() ?? [];

// never override the following keys if at least one is already set
Expand Down
1 change: 1 addition & 0 deletions tests/Fixtures/TestBundle/Entity/Issue5793/BagOfTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class BagOfTests

#[ORM\OneToMany(mappedBy: 'bagOfTests', targetEntity: TestEntity::class)]
#[Groups(['read', 'write'])]
#[ApiProperty(schema: ['type' => 'string'], jsonSchemaContext: ['foo' => 'bar'])]
private Collection $tests;

#[ORM\OneToMany(mappedBy: 'bagOfTests', targetEntity: NonResourceTestEntity::class)]
Expand Down
6 changes: 2 additions & 4 deletions tests/JsonSchema/Command/JsonSchemaGenerateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,8 @@ public function testArraySchemaWithReference(): void
$json = json_decode($result, associative: true);

$this->assertEquals($json['definitions']['BagOfTests.jsonld-write']['properties']['tests'], [
'type' => 'array',
'items' => [
'$ref' => '#/definitions/TestEntity.jsonld-write',
],
'type' => 'string',
'foo' => 'bar',
]);

$this->assertEquals($json['definitions']['BagOfTests.jsonld-write']['properties']['nonResourceTests'], [
Expand Down