Repository navigation
Description
Problem
OSW.fetch_schema fails in datamodel-code-generator when a schema references another page whose content sits in $defs/manual, and the referencing node has a key beside its $ref:
Exception: A Parser can not resolve classes:
[class: Test.json# references: frozenset({'Test.json#/$defs/manual'})]
The pointer #/$defs/manual belongs to the referenced page, but the error shows it looked up in the referencing document.
Reproduced on stage (8a059eb, oold 2.3.0, datamodel-code-generator 0.51.0).
Background
The OSW to OO-LD migration adds a hand_authored flag to CharacteristicType (Category:OSWffe74f291d354037b318c422591c5023). A hand-authored Characteristic keeps its hand-written schema in $defs/manual. The generated section points to it, so the stored jsonschema has this shape (abridged):
{
"allOf": [{ "$ref": "#/$defs/generated" }],
"title": "WikiFile",
"$defs": {
"generated": { "allOf": [{ "$ref": "#/$defs/manual" }], "uuid": "...", "title": "GeneratedWikiFile" },
"manual": { "anyOf": ["..."] }
}
}The CharacteristicType schema template writes the title* of an array property into items, beside the $ref, so almost every reference to such a Characteristic has a key beside its $ref:
"data_sheet": {
"type": "array",
"items": {
"title": "data_sheet",
"title*": { "en": "Data sheet", "de": "Datenblatt" },
"$ref": "/wiki/Category:OSWecdd611a465343d6b7b7030d4486218c?action=raw&slot=jsonschema"
}
}Minimal reproduction
Two pages, given to fetch_schema as offline_pages:
// Category:Item
{ "allOf": [{ "$ref": "#/$defs/manual" }],
"$defs": { "manual": { "type": "string" } } }
// Category:Test
{ "type": "object", "title": "Test",
"properties": { "files": { "type": "array",
"items": { "title*": { "en": "x" },
"$ref": "/wiki/Category:Item?action=raw&slot=jsonschema" } } } }Item reaches its content through |
Keys beside $ref in Test |
Result |
|---|---|---|
$defs/manual |
none | ok |
$defs/manual |
title |
ok |
$defs/manual |
title*, description* or an invented key |
fails |
$defs/x |
title* |
fails |
$defs/generated |
title* |
ok |
the root, no $defs |
title* |
ok |
$defs/generated works because fetch_schema merges it into the root with merge_generated_definitions (oold) before code generation. No other $defs entry is merged.
Proposed fix
After merge_generated_definitions, also merge $defs/manual into the root, with the same semantics: remove every root reference to #/$defs/manual (root $ref and allOf entries), merge the content so that existing root keys win, and remove $defs/manual. An unreferenced $defs/manual stays unchanged. Pointers below #/$defs/manual/... are not rewritten, as for generated.
Activity
Revert "fix(core): flatten $defs/manual before schema code generation (…
fix(core): resolve local root pointers of fetched schemas (#229)
LukasGold commentedon Dec 3, 2026
#230 now fixes this generically instead of flattening
$defs/manual.manual. datamodel-code-generator copies the root of a referenced page into the referencing node when that node has a key beside its$refthat is not metadata-only, such astitle*(title,description,$comment,examples,defaultandx-keys do not count). A local pointer of the referenced page, such as#/$defs/other, is then looked up in the referencing document. The minimal reproduction above fails in the same way with#/$defs/other.$refand the rootallOfof every fetched page with ajsonschemaslot. It merges the target into the root, and the keys at the root win. A local pointer in the root$refdid not fail before, but the field got the typeAny.anyOf/oneOfand insidepropertiesare not resolved and still fail in the same way.$defs/manualis not an OSW convention. Hand-written content sits at the schema root, and$defs/generatedis the only reserved section. The OO-LD migration no longer writes$defs/manual.title*beside the$refof an array item, stays unchanged. The failure occurs for local pointers in the rootallOf,anyOforoneOfof a referenced page and inside itsproperties, independent of the template, and a template change would change the generated section of every category that uses the template.