-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When generating TypeScript Angular code for an OpenAPI schema that contains a map property with an array of inline enums (e.g., additionalProperties with type: array of enum), the generated code produces an invalid type reference InnerEnum instead of the correct qualified enum name.
openapi-generator version
Version 7.10 can compile (but enum is not present), versions 7.11 - 7.19 generate invalid models.
OpenAPI declaration file content or url
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i https://gist.github.com/saxicek/48d09e5335a266cf316af4924237626e/raw/0b68148756a57a8bbaad4c60634a2e48dbdb4231/inner_enum.yaml \
-g typescript-angular \
-o ./typescript-angularSteps to reproduce
Generate using:
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
-i https://gist.github.com/saxicek/48d09e5335a266cf316af4924237626e/raw/0b68148756a57a8bbaad4c60634a2e48dbdb4231/inner_enum.yaml \
-g typescript-angular \
-o ./typescript-angularActual output for status.ts - notice the Array<InnerEnum>:
export interface Status {
options?: { [key: string]: Array<InnerEnum>; };
}
export namespace Status {
export const OptionsEnum = {
Ab01: 'AB01',
Ab02: 'AB02',
Ab03: 'AB03'
} as const;
export type OptionsEnum = typeof OptionsEnum[keyof typeof OptionsEnum];
}The options property references InnerEnum which is never defined, causing TypeScript compilation errors.
Expected output:
export interface Status {
options?: { [key: string]: Array<Status.OptionsEnum>; };
}
export namespace Status {
export const OptionsEnum = {
Ab01: 'AB01',
Ab02: 'AB02',
Ab03: 'AB03'
} as const;
export type OptionsEnum = typeof OptionsEnum[keyof typeof OptionsEnum];
}Related issues/PRs
#20877 - but that is not mentioning typescript-angular.
Suggest a fix
In DefaultCodegen.updateDataTypeWithEnumForMap(), the datatypeWithEnum is set using toEnumName(baseItem) which derives the enum name from the inner item's name ("inner" from additionalProperties), producing InnerEnum. However, the actual enum generated by templates uses property.enumName (e.g., OptionsEnum), causing a mismatch.