Skip to content

Commit 1cda6cf

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 1cda6cf

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
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;
@@ -160,6 +161,11 @@ public function buildSchema(string $className, string $format = 'jsonld', string
160161
['$ref' => $prefix.$jsonKey],
161162
]]);
162163

164+
// ensure the JSON format definition is present
165+
if (!isset($definitions[$jsonKey])) {
166+
$definitions[$jsonKey] = $jsonDefinition;
167+
}
168+
163169
if (isset($definitions[$jsonKey]['description'])) {
164170
$allOf['description'] = $definitions[$jsonKey]['description'];
165171
}

0 commit comments

Comments
Ā (0)