Skip to content

Commit edf29db

Browse files
Copilotsoyuka
andcommitted
Fix Hydra example type - use @type instead of type
Co-authored-by: soyuka <1321971+soyuka@users.noreply.github.com>
1 parent 3d23e0a commit edf29db

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/Hydra/JsonSchema/SchemaFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ public function buildSchema(string $className, string $format = 'jsonld', string
229229
],
230230
'example' => [
231231
'@id' => 'string',
232-
'type' => 'string',
232+
'@type' => 'string',
233233
$hydraPrefix.'first' => 'string',
234234
$hydraPrefix.'last' => 'string',
235235
$hydraPrefix.'previous' => 'string',

tests/Functional/JsonSchema/JsonLdJsonSchemaTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,26 @@ public function testSchemaJsonLdCollection(): void
163163
$this->assertEquals(['$ref' => '#/definitions/BagOfTests.jsonld-read'], $schema['allOf'][1]['properties']['hydra:member']['items']);
164164
}
165165

166+
public function testHydraCollectionBaseSchemaExample(): void
167+
{
168+
$schema = $this->schemaFactory->buildSchema(BagOfTests::class, 'jsonld', forceCollection: true);
169+
170+
$this->assertArrayHasKey('HydraCollectionBaseSchema', $schema['definitions']);
171+
$hydraCollectionSchema = $schema['definitions']['HydraCollectionBaseSchema'];
172+
173+
// Navigate to the hydra:view property example
174+
$this->assertArrayHasKey('allOf', $hydraCollectionSchema);
175+
$viewProperty = $hydraCollectionSchema['allOf'][1]['properties']['hydra:view'] ?? null;
176+
$this->assertNotNull($viewProperty, 'hydra:view property should exist');
177+
178+
// Check that the example uses @type instead of type
179+
$this->assertArrayHasKey('example', $viewProperty);
180+
$example = $viewProperty['example'];
181+
$this->assertArrayHasKey('@type', $example, 'Example should use @type with @ prefix');
182+
$this->assertArrayNotHasKey('type', $example, 'Example should not use type without @ prefix');
183+
$this->assertArrayHasKey('@id', $example, 'Example should have @id');
184+
}
185+
166186
public function testArraySchemaWithMultipleUnionTypes(): void
167187
{
168188
$schema = $this->schemaFactory->buildSchema(Nest::class, 'jsonld', 'output');

0 commit comments

Comments
 (0)