Skip to content

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

@ThomasM-coder

Description

@ThomasM-coder

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

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions