Bug report
Description
When using multiple .avsc files where one schema references a named type (record/enum/fixed) defined in another file, avrodoc-plus throws a browser console error if the referenced file sorts alphabetically after the referencing file:
Uncaught Unknown type name "com.example.enums.LogLevel" at logLevel
Root cause
In public/js/avrodoc.js, schemas share a single shared_types registry and are processed in the order they are provided (reflecting alphabetical filename order from the CLI). In public/js/schema.js, type references are resolved eagerly during parsing. Since complex/references_external_types.avsc is parsed before enums/loglevel.avsc, the referenced type is not yet in shared_types when the logLevel field is resolved.
The shared_types registry is shared across all files, so the approach would work if schemas were processed in dependency order — types defined before types that reference them.
Reproduction
- Create two schemas in the same input directory:
enums/log_level.avsc
{
"type": "enum",
"name": "LogLevel",
"namespace": "com.example",
"symbols": ["DEBUG", "INFO", "WARN", "ERROR"]
}
complex/composite.avsc (processed before enums/ alphabetically)
{
"type": "record",
"name": "Composite",
"namespace": "com.example",
"fields": [
{ "name": "level", "type": "com.example.LogLevel" }
]
}
- Run:
npx @mikaello/avrodoc-plus -i schemas -o out.html
- Open
out.html — browser console shows: Uncaught Unknown type name "com.example.LogLevel" at level
Expected behaviour
Cross-file type references should resolve regardless of filename sort order. Possible fixes:
- Two-pass resolution in the browser JS: first pass registers all named types from all schemas; second pass resolves field type references.
- Topological sort in the CLI: before embedding schemas in the HTML, sort them so definitions always precede their references.
Environment
Bug report
Description
When using multiple
.avscfiles where one schema references a named type (record/enum/fixed) defined in another file, avrodoc-plus throws a browser console error if the referenced file sorts alphabetically after the referencing file:Root cause
In
public/js/avrodoc.js, schemas share a singleshared_typesregistry and are processed in the order they are provided (reflecting alphabetical filename order from the CLI). Inpublic/js/schema.js, type references are resolved eagerly during parsing. Sincecomplex/references_external_types.avscis parsed beforeenums/loglevel.avsc, the referenced type is not yet inshared_typeswhen thelogLevelfield is resolved.The
shared_typesregistry is shared across all files, so the approach would work if schemas were processed in dependency order — types defined before types that reference them.Reproduction
enums/log_level.avsc{ "type": "enum", "name": "LogLevel", "namespace": "com.example", "symbols": ["DEBUG", "INFO", "WARN", "ERROR"] }complex/composite.avsc(processed beforeenums/alphabetically){ "type": "record", "name": "Composite", "namespace": "com.example", "fields": [ { "name": "level", "type": "com.example.LogLevel" } ] }npx @mikaello/avrodoc-plus -i schemas -o out.htmlout.html— browser console shows:Uncaught Unknown type name "com.example.LogLevel" at levelExpected behaviour
Cross-file type references should resolve regardless of filename sort order. Possible fixes:
Environment
@mikaello/avrodoc-plusversion: 1.5.0