Skip to content

Commit 10ebeab

Browse files
committed
fix: šŸ› if resource doesn't have 'json' schema, embed it instead of referencing it
There may be resources that don't have the 'json' schema but only the 'jsonld' schema, so in that case embed the json schema instead of referencing it.
1 parent 900f4fb commit 10ebeab

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

ā€Žsrc/Hydra/JsonSchema/SchemaFactory.phpā€Ž

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ public function buildSchema(string $className, string $format = 'jsonld', string
137137
$definitionName .= '.input';
138138
}
139139

140-
$jsonSchema = $this->schemaFactory->buildSchema($className, 'json', $type, $operation, null, $serializerContext, $forceCollection);
140+
$jsonSchema = $this->schemaFactory->buildSchema($className, 'json', $type, $operation, new Schema(version: $schema->getVersion()), $serializerContext, $forceCollection);
141141
$jsonKey = $jsonSchema->getRootDefinitionKey() ?? $jsonSchema->getItemsDefinitionKey();
142+
$jsonDefinition = $jsonSchema->getDefinitions()[$jsonKey] ?? null;
142143

143144
if (!$collectionKey) {
144145
$schema['$ref'] = $prefix.$definitionName;
@@ -157,7 +158,7 @@ public function buildSchema(string $className, string $format = 'jsonld', string
157158

158159
$allOf = new \ArrayObject(['allOf' => [
159160
['$ref' => $prefix.$baseName],
160-
['$ref' => $prefix.$jsonKey],
161+
isset($definitions[$jsonKey]) ? ['$ref' => $prefix.$jsonKey] : $jsonDefinition,
161162
]]);
162163

163164
if (isset($definitions[$jsonKey]['description'])) {

0 commit comments

Comments
Ā (0)