Summary
swagger-typescript-api does not correctly interpret OpenAPI 3.1 schemas that use a nullable object type expressed as a union:
{
"type": ["null", "object"],
"additionalProperties": { "type": "string" }
}
This is valid OpenAPI 3.1 syntax, and indicates:
a nullable object whose keys are strings and whose values are strings.
However, the current generator outputs:
Which loses all typing information.
Expected Output
labels?: Record<string, string> | null;
Actual Output
Why This Is Incorrect
-
"object" with "additionalProperties": { "type": "string" } should always map to Record<string, string>.
-
Wrapping "type": ["null", "object"] should become Record<string, string> | null.
-
Instead, the union collapses to generic object, discarding key/value types.
Minimal Reproduction
{
"openapi": "3.1.0",
"components": {
"schemas": {
"Test": {
"type": ["null", "object"],
"additionalProperties": { "type": "string" }
}
}
}
}
Generated TypeScript:
export type Test = null | object;
Expected:
export type Test = Record<string, string> | null;
Root of the Issue
The generator appears to:
-
Recognize "type": "object" case
-
But not recognize "type": ["object"] or "type": ["null", "object"] cases
-
And therefore falls back to generic object
This breaks any nullable dictionary schema.
Impact
All APIs using OpenAPI 3.1 unions for nullable dictionaries generate unsafe and incorrect TypeScript definitions
Summary
swagger-typescript-api does not correctly interpret OpenAPI 3.1 schemas that use a nullable object type expressed as a union:
This is valid OpenAPI 3.1 syntax, and indicates:
a nullable object whose keys are strings and whose values are strings.
However, the current generator outputs:
Which loses all typing information.
Expected Output
Actual Output
Why This Is Incorrect
"object" with "additionalProperties": { "type": "string" } should always map to Record<string, string>.
Wrapping "type": ["null", "object"] should become Record<string, string> | null.
Instead, the union collapses to generic object, discarding key/value types.
Minimal Reproduction
Generated TypeScript:
Expected:
Root of the Issue
The generator appears to:
Recognize "type": "object" case
But not recognize "type": ["object"] or "type": ["null", "object"] cases
And therefore falls back to generic object
This breaks any nullable dictionary schema.
Impact
All APIs using OpenAPI 3.1 unions for nullable dictionaries generate unsafe and incorrect TypeScript definitions