Bug Report Checklist
Description
When the same external schema file is referenced via $ref from multiple external JSON schema files that are themselves composed via allOf, the generator creates duplicate model classes instead of reusing the same named model. The duplicate is suffixed with 1 (e.g. ContainerMapping and ContainerMapping1). All field usages reference ContainerMapping1, leaving ContainerMapping as an unused orphan.
openapi-generator version
openapitools/openapi-generator-cli:v7.22.0
OpenAPI declaration file content or url
Full spec: https://github.com/bbc/tams/blob/main/api/TimeAddressableMediaStore.yaml (multi-file, references schemas in api/schemas/)
Minimal structure to reproduce:
TimeAddressableMediaStore.yaml (root spec):
paths:
/flows:
get:
responses:
"200":
content:
application/json:
schema:
type: array
items:
$ref: schemas/flow.json
components: {}
schemas/flow.json:
{
"title": "Flow",
"type": "object",
"oneOf": [
{ "$ref": "flow-video.json" },
{ "$ref": "flow-audio.json" }
]
}
schemas/flow-video.json:
{
"title": "Video Flow",
"type": "object",
"allOf": [
{ "$ref": "flow-core.json" },
{
"type": "object",
"properties": {
"format": { "type": "string" }
}
}
]
}
schemas/flow-core.json:
{
"title": "Flow Core",
"type": "object",
"properties": {
"container_mapping": {
"$ref": "container-mapping.json"
},
"flow_collection": {
"$ref": "flow-collection.json"
}
}
}
schemas/flow-collection.json:
{
"title": "Flow Collection",
"type": "array",
"items": {
"type": "object",
"properties": {
"container_mapping": {
"$ref": "container-mapping.json"
}
}
}
}
schemas/container-mapping.json:
{
"title": "Container Mapping",
"type": "object",
"properties": {
"track_index": { "type": "integer" }
}
}
Generation Details
docker run --rm \
-v $(pwd):/local \
openapitools/openapi-generator-cli:v7.22.0 generate \
-i /local/TimeAddressableMediaStore.yaml \
-g rust-axum \
-o /local/rust_server \
--additional-properties=packageName=tams-api-server,generateAliasAsModel=true
Same behaviour observed with -g python-fastapi.
Steps to reproduce
- Create the multi-file spec structure above.
- Run the generator against the root YAML.
- Inspect the generated models —
ContainerMapping and ContainerMapping1 are both present. All container_mapping fields reference ContainerMapping1.
Related issues/PRs
Both describe the same root cause and remain unresolved.
Suggest a fix
The generator correctly deduplicates schemas registered in components/schemas when referenced via $ref: '#/components/schemas/<Name>'. The limitation is specific to schemas encountered indirectly through cross-file allOf chains — the generator resolves each external $ref independently rather than checking whether the resolved file path has already been named.
Attempts to work around in the spec:
- Adding
container-mapping.json to components/schemas in the root spec: ContainerMapping1 is still generated when walking the allOf chains.
- Changing the external JSON files to back-reference the root spec via
"$ref": "../root.yaml#/components/schemas/ContainerMapping": the generator treats the cross-document path as a distinct external reference and still inlines the content.
Workaround: generating from a pre-bundled spec (e.g. via Redocly CLI bundle) resolves the duplicates, as the bundler collapses all external $refs into a single components/schemas entry per schema before the generator processes the spec.
The fix would be for the generator to deduplicate schemas by resolved absolute file path, so that the same file encountered in different resolution contexts produces one named model rather than multiple.
Bug Report Checklist
Description
When the same external schema file is referenced via
$reffrom multiple external JSON schema files that are themselves composed viaallOf, the generator creates duplicate model classes instead of reusing the same named model. The duplicate is suffixed with1(e.g.ContainerMappingandContainerMapping1). All field usages referenceContainerMapping1, leavingContainerMappingas an unused orphan.openapi-generator version
openapitools/openapi-generator-cli:v7.22.0OpenAPI declaration file content or url
Full spec: https://github.com/bbc/tams/blob/main/api/TimeAddressableMediaStore.yaml (multi-file, references schemas in
api/schemas/)Minimal structure to reproduce:
TimeAddressableMediaStore.yaml(root spec):schemas/flow.json:{ "title": "Flow", "type": "object", "oneOf": [ { "$ref": "flow-video.json" }, { "$ref": "flow-audio.json" } ] }schemas/flow-video.json:{ "title": "Video Flow", "type": "object", "allOf": [ { "$ref": "flow-core.json" }, { "type": "object", "properties": { "format": { "type": "string" } } } ] }schemas/flow-core.json:{ "title": "Flow Core", "type": "object", "properties": { "container_mapping": { "$ref": "container-mapping.json" }, "flow_collection": { "$ref": "flow-collection.json" } } }schemas/flow-collection.json:{ "title": "Flow Collection", "type": "array", "items": { "type": "object", "properties": { "container_mapping": { "$ref": "container-mapping.json" } } } }schemas/container-mapping.json:{ "title": "Container Mapping", "type": "object", "properties": { "track_index": { "type": "integer" } } }Generation Details
docker run --rm \ -v $(pwd):/local \ openapitools/openapi-generator-cli:v7.22.0 generate \ -i /local/TimeAddressableMediaStore.yaml \ -g rust-axum \ -o /local/rust_server \ --additional-properties=packageName=tams-api-server,generateAliasAsModel=trueSame behaviour observed with
-g python-fastapi.Steps to reproduce
ContainerMappingandContainerMapping1are both present. Allcontainer_mappingfields referenceContainerMapping1.Related issues/PRs
Both describe the same root cause and remain unresolved.
Suggest a fix
The generator correctly deduplicates schemas registered in
components/schemaswhen referenced via$ref: '#/components/schemas/<Name>'. The limitation is specific to schemas encountered indirectly through cross-fileallOfchains — the generator resolves each external$refindependently rather than checking whether the resolved file path has already been named.Attempts to work around in the spec:
container-mapping.jsontocomponents/schemasin the root spec:ContainerMapping1is still generated when walking theallOfchains."$ref": "../root.yaml#/components/schemas/ContainerMapping": the generator treats the cross-document path as a distinct external reference and still inlines the content.Workaround: generating from a pre-bundled spec (e.g. via Redocly CLI
bundle) resolves the duplicates, as the bundler collapses all external$refs into a singlecomponents/schemasentry per schema before the generator processes the spec.The fix would be for the generator to deduplicate schemas by resolved absolute file path, so that the same file encountered in different resolution contexts produces one named model rather than multiple.