Skip to content

Commit

Permalink
fix(jsonschema): field with unknown_type (#5869)
Browse files Browse the repository at this point in the history
  • Loading branch information
romainallanot authored Oct 5, 2023
1 parent 9947f88 commit 1d38e9c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
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',
]);
}
}

0 comments on commit 1d38e9c

Please sign in to comment.