OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Typescript-Node] Import mappings does not allow multiple imports from the same package
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- 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
Having an issue with importMappings when generating a typescript-node client. However, this looks like an issue in the DefaultGenerator so I wanted to bring up here:
If I use this OpenAPI PetStore Spec to generate the client and I assume I have all the types defined in a library called @company/prefix-zoo-store, the generated client correct recognizes a single model in the importMapping but if I have more than one, it shows an interesting log in the generation and:
Creates the model for the type which import model specified
Does not import either the model from the generated or the import mapping in the client which it created.
Some
openapi-generator version
v5-beta2
OpenAPI declaration file content or url
https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml
Generation Details
openapi.config.json is :
{
"generatorName": "typescript-node",
"additionalProperties": {
"npmName": "pet-model-node-client",
"npmRepository" : "http://pet",
"npmVersion": "1.0.0",
"supportsES6": true
},
"importMappings": {
"Pet": "@company/prefix-zoo-store",
"Pets": "@company/prefix-zoo-store"
"Error": "@company/prefix-zoo-store"
}
}
docker run --rm -v ${PWD}:/local openapitools/openapi-generator-cli generate \
-i https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml \
-c /local/openapi.config.json \
-o /local/client
Expected
import { Pet, Pets, Error } from '@company/prefix-zoo-store';
Actual
Here is the log in the generation:
[main] INFO o.o.codegen.TemplateManager - Skipped /local/src/model/@company/prefix-zoo-store.ts (Skipped prior to model processing due to import mapping conflict (either by user or by generator).)
[main] INFO o.o.codegen.TemplateManager - Skipped /local/src/model/@company/prefix-zoo-store.ts (Skipped prior to model processing due to import mapping conflict (either by user or by generator).)
The import section of the client only has:
import { Pet } from '@company/prefix-zoo-store';
Fix
The error seems to arise from https://github.com/OpenAPITools/openapi-generator/blame/41851b45e1f1ffa7f0df36270a6b3c0cee6425bb/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java#L442
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 at DefaultGenerator.java around the import-mapping logic identified in the issue, then reproduce the typescript-node client with the Petstore specification, openapi.config.json, and the provided Docker command. Compare generation logs and the generated client's imports for multiple models mapped to one package. Done means all mapped models are imported from that package without generating conflicting model files.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, java, node.js, typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100