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

[FIX][typescript-fetch] Fix self import for models with a discriminator

Open GeroSchaarmann opened this issue 2 years ago • 11 comments

This PR will fix issue #15637 .

In this PR the modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache file was edited, by removing the self import for the discriminator models.

To validate the work use ./bin/generate-samples.sh bin/configs/typescript-fetch-self-import-issue.yaml once with and once without the fix and compare the files it generates.

PR checklist

  • [x] Read the contribution guidelines.
  • [x] Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • [x] Run the following to build the project and update samples:
    ./mvnw clean package 
    ./bin/generate-samples.sh
    ./bin/utils/export_docs_generators.sh
    
    Commit all changed files. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*. For Windows users, please run the script in Git BASH.
  • [x] In case you are adding a new generator, run the following additional script :
    ./bin/utils/ensure-up-to-date
    
    Commit all changed files.
  • [x] File the PR against the correct branch: master (6.3.0) (minor release - breaking changes with fallbacks), 7.0.x (breaking changes without fallbacks)
  • [x] If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

GeroSchaarmann avatar May 25 '23 08:05 GeroSchaarmann

Hello, is this still beeing worked on?

Digirik avatar Aug 30 '23 06:08 Digirik

I just noticed that Gero did not mention the technical committee :)

@TiFu (2017/07) @taxpon (2017/07) @sebastianhaas (2017/07) @kenisteward (2017/07) @Vrolijkx (2017/09) @macjohnny (2018/01) @topce (2018/10) @akehir (2019/07) @petejohansonxo (2019/11) @amakhrov (2020/02) @davidgamero (2022/03) @mkusaka (2022/04)

Nikos410 avatar Sep 07 '23 07:09 Nikos410

Is there still being worked on? I'm having the same issue. If I build my project with the legacyDiscriminatorBehavior=false flag, I get multiple duplicate errors like this one: duplicate identifier for legacyDiscriminatorBehavior = false

ajansen95 avatar Oct 26 '23 15:10 ajansen95

@GeroSchaarmann do you want to fix the conflicts?

macjohnny avatar Nov 01 '23 10:11 macjohnny

Any update? We have the same problem and need to remove the imports manually.

Angi2412 avatar Nov 20 '23 13:11 Angi2412

Would love to see this go though in the next milestone/version. I am currently having issues with this on a project and would love to not have to modify the generated API code at all.

joshuamolden avatar Mar 28 '24 21:03 joshuamolden

I see this got moved to the next release again. Can this please be resolved in 7.6.0?

joshuamolden avatar Apr 17 '24 20:04 joshuamolden

@joshuamolden you can e.g. clone this PR and fix the conflicts to move this forward

macjohnny avatar Apr 22 '24 07:04 macjohnny

True! Didn't even think of that! I'll take a stab!

joshuamolden avatar Apr 22 '24 13:04 joshuamolden

It seems like the fix would either be:

  1. Updating this modelGeneric.mustache file to properly account for discriminators being present
  • The original author tried to modify this file, but I don't think his changes actually fixed the issue: https://github.com/OpenAPITools/openapi-generator/pull/15638#discussion_r1265614448
  1. Controlling the values passed to this mustache file so that it can't make duplicate imports with based on the current mustache template.

I am not sure how to go about option 2, so I think option 1 is most viable.

joshuamolden avatar Apr 24 '24 16:04 joshuamolden

I noticed on my project that I had legacyDiscriminatorBehavior set to false. I switched it to true and my code didn't seem to generate with the same issues this ticket is addressing. I would rather not have to opt into the legacy behavior though, so it would still be nice to resolve this ticket.

joshuamolden avatar Apr 24 '24 16:04 joshuamolden

Due to this PR not being developed any further I forked the branch and opened an updated PR here.

Digirik avatar Jul 18 '24 11:07 Digirik

@macjohnny This can be closed aswell i think. (:

Digirik avatar Jul 18 '24 14:07 Digirik