OpenAPITools / OpenAPITools/openapi-generator

[typescript-node] Specifying the --model-name-suffix CLI argument leads to generating incorrect imports in models

Open
#8,959 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Client: TypeScript
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
  1. Make a folder for customized code generator tempates, e.g. mkdir templates && cd templates
  2. Extract the templates with npx @openapitools/openapi-generator-cli author template -g typescript-node
  3. Open model.mustache in a text editor
  4. On line 6, replace import { {{classname}} } from '{{filename}}'; with import { {{classname}} } from './{{classname}}';
  5. Save the modified model.mustache
  6. Specify the customized templates with the -t templates CLI argument

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.