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

[Java][Spring] Remove extra tag in template causing each operation to appear twice - issue 11570

Open GregDThomas opened this issue 2 years ago • 9 comments

This fixes https://github.com/OpenAPITools/openapi-generator/issues/11570 by removing the unnecessary tags at the class level. A tag appears in the spec at an operation level - https://swagger.io/docs/specification/grouping-operations-with-tags/

So applying these tags at a controller level is unnecessary. And if you do, the operation appears twice when rendered by a swagger generator, once grouped under the tag for the controller, and once under the tag for the method.

@cachescrubber @welshm @MelleD @borsch @Zomzog

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] File the PR against the correct branch: master (6.1.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.

GregDThomas avatar Sep 15 '22 16:09 GregDThomas

I'm surprised there's no generated examples that ended up changing because of this... maybe one should be added?

Happy to do so; I had a look but couldn't see anything obvious, is there an existing sample you could point me at that shows how an example is generated? Thanks.

I assume this has no impact on projects using interfaceOnly

Sorry - I should have probably been clearer in my explanation. The tags are applied in the interface - both at the class (prior to this PR) and method level. Any generated Controller class that implements the interface doesn't have any tags just inherits the ones from the interface - so this has an effect regardless of the use of interfaceOnly

GregDThomas avatar Sep 15 '22 17:09 GregDThomas

Ah, wait. Just found the ./bin/generate-samples.sh file. Will have a look at that properly, probably tomorrow now.

GregDThomas avatar Sep 15 '22 18:09 GregDThomas

Here you go; samples updated to reflect the new template.

GregDThomas avatar Sep 16 '22 09:09 GregDThomas

@GregDThomas can you please update the sample?

	modified:   samples/openapi3/client/petstore/spring-stubs/src/main/java/org/openapitools/api/PetApi.java
	modified:   samples/openapi3/client/petstore/spring-stubs/src/main/java/org/openapitools/api/StoreApi.java
	modified:   samples/openapi3/client/petstore/spring-stubs/src/main/java/org/openapitools/api/UserApi.java
	modified:   samples/server/petstore/spring-boot-nullable-set/src/main/java/org/openapitools/api/NullableApi.java
	modified:   samples/server/petstore/spring-stubs/src/main/java/org/openapitools/api/PetApi.java
	modified:   samples/server/petstore/spring-stubs/src/main/java/org/openapitools/api/StoreApi.java
	modified:   samples/server/petstore/spring-stubs/src/main/java/org/openapitools/api/UserApi.java

no changes added to commit (use "git add" and/or "git commit -a")

This script runs in pull requests against the anticipated merge commit (as if the PR was merged now).
When you see unexpected files here, it likely means that there are newer commits in master that you need to 
rebase or merge into your branch.

Please run 'bin/generate-samples.sh' locally and commit changes (UNCOMMITTED CHANGES ERROR)
Error: Process completed with exit code 1.

ref: https://github.com/OpenAPITools/openapi-generator/actions/runs/3066652600/jobs/4993337458

wing328 avatar Sep 20 '22 05:09 wing328

@GregDThomas can you please update the sample?

@wing328 All done.

Apologies, when using Git Bash on Windows the sample regeneration changes more than than just the expected files; line endings all change - which I could probably sort with the correct Git setting - but there are also changes in some of the .md files - particularly a "\n" sequence being replaced with a literal carriage return and loss of white space. So I just re-generated the samples for the "spring-boot*" configs - and missed a few.

EDIT: A sudden though struck me. I re-ran the sample generation using WSL instead of Git Bash. That did the right thing, and only made the expected changes. Something for me to remember if I submit a PR in the future.

GregDThomas avatar Sep 20 '22 09:09 GregDThomas

EDIT: A sudden though struck me. I re-ran the sample generation using WSL instead of Git Bash. That did the right thing, and only made the expected changes. Something for me to remember if I submit a PR in the future.

Thanks for sharing. I remember some users reported issues with WSL before. Maybe that has been fixed, which is good.

wing328 avatar Sep 20 '22 13:09 wing328

Rebased after release 6.2.0.

Is there anything else I need to do to get this over the line, or do I just need to be patient?

GregDThomas avatar Oct 09 '22 17:10 GregDThomas

I'll try to take another look this week.

wing328 avatar Oct 09 '22 17:10 wing328

(Sorry, had to push another commit, with some more samples added to the PR, tripped up again by a bad wildcard)

GregDThomas avatar Oct 09 '22 18:10 GregDThomas

I just rebased this - and also improved the way it works.

A colleague highlighted that without a tag name/description at the controller level, one doesn't appear in the generated Swagger UI. So instead, this now keeps tags at both controller and operation level but ensures that they use the same tag name (previously the "controller" level tag used the "base" name, created from the name of the controller, which is similar to, but not quite the same as, the name of the first tag of the first operation of that controller).

GregDThomas avatar Nov 10 '22 09:11 GregDThomas

NB. CI failed because of an I/O issue with Maven central. I don't have priv's to retry it ...

Failed to execute goal on project openapi-generator-online: Could not resolve dependencies for project org.openapitools:openapi-generator-online:jar:6.3.0-SNAPSHOT: Could not transfer artifact org.springframework.boot:spring-boot-autoconfigure:jar:2.7.5 from/to central (https://repo.maven.apache.org/maven2): transfer failed for https://repo.maven.apache.org/maven2/org/springframework/boot/spring-boot-autoconfigure/2.7.5/spring-boot-autoconfigure-2.7.5.jar: Connect to repo.maven.apache.org:443 [repo.maven.apache.org/146.75.32.215] failed: Connection timed out (Connection timed out) -> [Help 1]

GregDThomas avatar Nov 10 '22 09:11 GregDThomas

(rebased again)

GregDThomas avatar Jan 06 '23 16:01 GregDThomas

@cachescrubber (2022/02) @welshm (2022/02) @MelleD (2022/02) @atextor (2022/02) @manedev79 (2022/02) @javisst (2022/02) @borsch (2022/02) @banlevente (2022/02) @Zomzog (2022/09)

GregDThomas avatar Jan 07 '23 13:01 GregDThomas

Unit tests are good 😄 - I've added shouldUseTheSameTagNameForTheInterfaceAndTheMethod_issue11570

GregDThomas avatar Jan 07 '23 15:01 GregDThomas

Unfortunately this didn't make 6.3; are they any changes you;'d like before it gets merged, or do I just need to be patient. Thanks!

GregDThomas avatar Feb 18 '23 10:02 GregDThomas

Thank you!

GregDThomas avatar Feb 18 '23 15:02 GregDThomas

Version 5.4.0 also have this issue. Do you have a plan to fix it in 5.x.x? And the bug issue is 5.4.0, too. Migration to 6.x.x is big deal.

mumubin avatar Mar 09 '23 07:03 mumubin