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
3 changes: 2 additions & 1 deletion src/JsonSchema/SchemaFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ private function buildPropertySchema(Schema $schema, string $definitionName, str
// or if property schema is already fully defined (type=string + format || enum)
$propertySchemaType = $propertySchema['type'] ?? false;

$isUnknown = 'array' === $propertySchemaType && Schema::UNKNOWN_TYPE === ($propertySchema['items']['type'] ?? null);
$isUnknown = Schema::UNKNOWN_TYPE === $propertySchemaType
|| ('array' === $propertySchemaType && Schema::UNKNOWN_TYPE === ($propertySchema['items']['type'] ?? null));

if (
!$isUnknown && (
Expand Down
19 changes: 18 additions & 1 deletion tests/Fixtures/TestBundle/Entity/Issue5793/BagOfTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,18 @@ class BagOfTests

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

#[ORM\OneToMany(mappedBy: 'bagOfTests', targetEntity: NonResourceTestEntity::class)]
#[Groups(['read', 'write'])]
private Collection $nonResourceTests;

#[ORM\ManyToOne(targetEntity: TestEntity::class)]
#[ORM\JoinColumn(name: 'type', referencedColumnName: 'id', nullable: false)]
#[Groups(['read', 'write'])]
protected ?TestEntity $type = null;

public function __construct()
{
$this->tests = new ArrayCollection();
Expand Down Expand Up @@ -128,4 +133,16 @@ public function removeNonResourceTest(NonResourceTestEntity $nonResourceTest): s

return $this;
}

public function getType(): ?TestEntity
{
return $this->type;
}

public function setType(?TestEntity $type): self
{
$this->type = $type;

return $this;
}
}
5 changes: 5 additions & 0 deletions tests/JsonSchema/Command/JsonSchemaGenerateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,10 @@ public function testArraySchemaWithReference(): void
$this->assertEquals($json['definitions']['BagOfTests.jsonld-write']['properties']['description'], [
'maxLength' => 255,
]);

$this->assertEquals($json['definitions']['BagOfTests.jsonld-write']['properties']['type'], [
'owl:maxCardinality' => 1,
'$ref' => '#/definitions/TestEntity.jsonld-write',
]);
}
}