OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.82k stars 6.58k forks source link

[BUG] [Typescript-Node] Import mappings does not allow multiple imports from the same package #7790

Open mahirk opened 4 years ago

mahirk commented 4 years ago

Bug Report Checklist

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

ankushjindal81 commented 3 years ago

@wing328 Is there any update on this?

Grochni commented 2 years ago

Is there any known workaround for this issue?