OpenAPITools / OpenAPITools/openapi-generator
[REQ] typescript-angular languageSpecificPrimitives
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
I have a model named Error and another one named Errors, containing a list of Error
For typescript-angular gernerator, Error is an element of the languageSpecificPrimitives list.
Therefore, the generated class/interface for Error will be ModelError.
But, for the Errors class, instead of using ModelError it still continues to use the language specific Error class:
export interface Errors {
errors?: Array<Error>;
}
Describe the solution you'd like
I would like:
- that the Errors class use ModelError class with the correct import
- to be able to customize the generated class name of a language specific primitive and the using classes to import that
Describe alternatives you've considered
As a workaround, I did these:
{
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "6.6.0",
"generators": {
"angular": {
"modelNameSuffix": "DTO",
"generatorName": "typescript-angular",
"inputSpec": "./openapi/api-v1.0.yaml",
"output": "src/app/api/v1.0",
"typeMappings": {
"Error": "\fError"
}
}
}
}
}
Note the suffix 'DTO' and the \f character in typeMappings. This correctly generates Error class as ErrorDTO class and generated ErrorsDTO is correct:
import { ErrorDTO } from './error';
export interface ErrorsDTO {
errors?: Array<ErrorDTO>;
}
If the \f (it works also with \n or \t or whatever escape character) character is missing, then the ErrorsDTO class stays unchanged.
Other possibility is the following:
{
"$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
"spaces": 2,
"generator-cli": {
"version": "6.6.0",
"generators": {
"angular": {
"generatorName": "typescript-angular",
"inputSpec": "./openapi/api-v1.0.yaml",
"output": "src/app/api/v1.0",
"typeMappings": {
"Error": "ModelError"
}
}
}
}
}
Note there is no more model suffix here. If suffix is added, the code is not good.
ErrorDTO class goes in error.ts and in ErrorsDTO we have an import from ./modelError which does not exist:
import { ModelErrorDTO } from './modelError';
export interface ErrorsDTO {
errors?: Array<ModelErrorDTO>;
}
Additional context
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue provides a typescript-angular generator configuration and generated Errors example, but names no implementation files or tests. Start by reproducing the case with the shown typeMappings and modelNameSuffix settings, then trace the typescript-angular model naming and import generation. Done means referenced language-specific primitives use the generated model name and a valid import, with customization working alongside a model suffix.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, openapi, typescript
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100