OpenAPITools / OpenAPITools/openapi-generator
[typescript-node] Specifying the --model-name-suffix CLI argument leads to generating incorrect imports in models
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
Specifying the --model-name-suffix CLI argument leads to generating incorrect imports in the model TypeScript files.
Namely, the suffix gets appended twice to the module name referenced in the import declaration. I.e. assuming that the generator was invoked with --model-name-suffix Model, it produces
import userModel from './userModelModel
instead of
import userModel from './userModel
openapi-generator version
@openapitools/openapi-generator-cli": "^2.2.1"
JAR version: 5.0.1
Command line used for generation
cross-env-shell TS_POST_PROCESS_FILE=\"node node_modules/prettier/bin-prettier.js --write\" npx @openapitools/openapi-generator-cli generate -i openapi.yaml -g typescript-node -o customerserviceapi --skip-validate-spec --model-name-suffix Model --additional-properties=supportsES6=true,enumPropertyNaming=original,generateAliasAsModel=false,enablePostProcessFile=true,nestVersion=7.5.1
Steps to reproduce
Generate the TypeScript files with the command line specified above. Unfortunately I cannot share the Open API spec as it's private - but it looks like an issue with the generator templates rather than with a specific OpenAPI spec.
Suggest a fix/enhancement
- Make a folder for customized code generator tempates, e.g.
mkdir templates && cd templates - Extract the templates with
npx @openapitools/openapi-generator-cli author template -g typescript-node - Open model.mustache in a text editor
- On line 6, replace
import { {{classname}} } from '{{filename}}';withimport { {{classname}} } from './{{classname}}'; - Save the modified model.mustache
- Specify the customized templates with the
-t templatesCLI argument
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
Start with the typescript-node generator's model.mustache template, especially the import declaration described in the issue, and reproduce the output using the supplied generation command with --model-name-suffix Model. Done means generated model files import the module with the suffix only once; the issue does not name a test to run.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100