openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

[BUG] [typescript-fetch] ModelNamePrefix is added twice to import statements thereby breaking the build

Open ThomasM2204 opened this issue 1 year ago • 0 comments

Bug Report Checklist

  • [x] Have you provided a full/minimal spec to reproduce the issue?
  • [x] Have you validated the input using an OpenAPI validator (example)?
  • [x] Have you tested with the latest master to confirm the issue still exists?
  • [x] Have you searched for related issues/PRs?
  • [x] What's the actual output vs expected output?
  • [ ] [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When generating the model files the prefix is properly added once in front of the generated files. However, in the import statements the prefix is added twice resulting in erroneous statements breaking the build.

When e.g. SomePrefix is set for modelNamePrefix, then the following model files are generated for example-for-file-naming-option.yaml:

  • SomePrefixPetCategory.ts
  • SomePrefixPet.ts

However, within SomePrefixPet.ts it looks like this:

import type { SomePrefixPetCategory } from './SomePrefixSomePrefixPetCategory';
import {
    SomePrefixPetCategoryFromJSON,
    SomePrefixPetCategoryFromJSONTyped,
    SomePrefixPetCategoryToJSON,
} from './SomePrefixSomePrefixPetCategory';

I.e. SomePrefix is added twice.

openapi-generator version

Issue started in version 7.6.0 and is still there in current master.

Version 7.5.0 is working fine.

OpenAPI declaration file content or url

It can be reproduced using modules/openapi-generator/src/test/resources/3_0/typescript-fetch/example-for-file-naming-option.yaml from the repo: https://github.com/OpenAPITools/openapi-generator/blob/v7.6.0/modules/openapi-generator/src/test/resources/3_0/typescript-fetch/example-for-file-naming-option.yaml

Generation Details
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate \
	-i modules/openapi-generator/src/test/resources/3_0/typescript-fetch/example-for-file-naming-option.yaml \
	-g typescript-fetch \
	--additional-properties modelNamePrefix=SomePrefix \
	-o generator_out/
Steps to reproduce

See command above

Related issues/PRs

Nothing found.

Suggest a fix

It's probably due to this PR which touched a bit of relevant code between 7.5.0 and 7.6.0: #18284

ThomasM2204 avatar Jun 30 '24 10:06 ThomasM2204