Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] bad import for SpringBoot model #3461

Closed
bademux opened this issue Jul 25, 2019 · 10 comments
Closed

[BUG] bad import for SpringBoot model #3461

bademux opened this issue Jul 25, 2019 · 10 comments

Comments

@bademux
Copy link

bademux commented Jul 25, 2019

The commit 0fca901 adds
`` `import org.openapitools.jackson.nullable.JsonNullable; ```

Why I need to import the class if I don't need it?

@bademux bademux changed the title [BUG] Description [BUG] bad import for SpringBoot model Jul 25, 2019
@macjohnny
Copy link
Member

cc @cbornet

@vmisra2018
Copy link

I also saw this. It is unused import and it forces to add dependency.

@Fjolnir-Dvorak
Copy link
Contributor

I think this issue is far bigger. In a lot of generators there are a heck of a ton unused imports in every file. My IDE really hates me for that since there are generated files which are not annotated as generated in the comments. I think the best option would be to make each single import conditional which would bloat the whole generator in its current state.

Each import would be associated with one or multiple features. If one or more of those features are used the import should be set as well as other conditional events like adding the dependency to the dependency management system.
That feature could be implemented as a base feature for all languages and after that could be adopted to each individual generator.

@RupprechJo
Copy link

The problem is even bigger, if you want to use the generator in build tool, after generating it does not compil witout removing that unused import, so you cannot use it in an automated build!

@jmini
Copy link
Member

jmini commented Aug 5, 2019

I have started to add google-java-format as post-generation step when I use OpenAPI-Generator.

It removes the unused imports and format the code.
There are gradle and maven plugins available.

@Fjolnir-Dvorak
Copy link
Contributor

@jmini That is a good solution to start with. But that only fixes the issue for Java. Since the generator is not java specific I tend to not like that as a final solution.

@bademux
Copy link
Author

bademux commented Aug 10, 2019

@jmini sound like a big hack. This kind of solution tends to hide problems. Why to not fix the bug as it perfectly visible and reproducible.

@jmini
Copy link
Member

jmini commented Aug 14, 2019

@bademux: feel free to propose a PR.

The problem is that the way the generator is built, the imports are written first and at this point in time the information to know if one of the field will use JsonNullable in the class content or not is not present.

@bademux
Copy link
Author

bademux commented Aug 15, 2019

@jmini Well, it a bit of a work to propose new generator :)
Anyway, thanks for discussion!

Closed as a "Won't fix" (until global generator context with all needed information will be passed)

@bademux bademux closed this as completed Aug 15, 2019
@jmini
Copy link
Member

jmini commented Aug 19, 2019

According to #3474 (comment), I think that @bkabrda added the code you wanted:

It also makes sure that the imports for JsonNullable are only added when at least one of the model's fields actually uses that.

Can you test with the latest SNAPSHOT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants