Skip to content

Generate unique operationIds only when there is a duplicate#542

Merged
ilopmar merged 3 commits into2.6.xfrom
issue-361
Aug 6, 2021
Merged

Generate unique operationIds only when there is a duplicate#542
ilopmar merged 3 commits into2.6.xfrom
issue-361

Conversation

@ilopmar
Copy link
Contributor

@ilopmar ilopmar commented Aug 4, 2021

Fixes #361

This PR reverts and improves the changes done in #498 to only generate unique operationIds when there is a duplicate. It modifies a bunch of tests that should have never been changed in the first place.

I've followed what Spring Boot does and only adds a suffix _number when there is a duplicate instead of doing it for every single operationId.

P.S: It's easier to review the PR as separate commits. The first one (a717c28) fixes the problem and the second (bcf992a) changes the tests to its original state.

@ilopmar ilopmar requested a review from jameskleeh August 4, 2021 11:30
@asodja
Copy link
Contributor

asodja commented Aug 4, 2021

Btw original implementation already did that, so it added indexes only if there was any duplicate. This is seen from Unit tests.
Also it was done in a way that only autogenerated operationids were deduplicated and not operation ids that were defined by the user.

The only breaking change was, that method name was attached at the end everytime. But this could be easily fixed :)

@ilopmar
Copy link
Contributor Author

ilopmar commented Aug 4, 2021

Btw original implementation already did that, so it added indexes only if there was any duplicate. This is seen from Unit tests.

No completely true, the original implementation also modified the first duplicate operationId adding a 1. In this implementation the first operationId is not modified and the second one is modified with _1. See https://github.com/micronaut-projects/micronaut-openapi/pull/542/files#diff-bc02d3ee7e696a0c68e33b82db5b9f9cabf443c78c771b1509650f086a21de4aL80-L81

@ilopmar
Copy link
Contributor Author

ilopmar commented Aug 4, 2021

This PR will be included in 2.6.1 release that will target Micronaut 2.5.x

@asodja
Copy link
Contributor

asodja commented Aug 4, 2021

No completely true, the original implementation also modified the first duplicate operationId adding a 1

I agree. But in that case there is no big difference. Because you cannot know what operation id was first if you don't track history.

For example you have:

class B {
    index()
} 

And then in next release you add:

class A {
    index()
} 

It's not possible to know what method was original with name index, so you might break user expected "operation id" value anyway. Maybe Micronaut could create even more unique operation ids, or just copy Spring behavior that will please most people :)

But good think you fixed that, so it does not break user experience, thank you! My bad that I added breaking behavior

@ilopmar
Copy link
Contributor Author

ilopmar commented Aug 4, 2021

I've copied Spring behavior for this with the suffix _1, _2,...

Don't need to apologies, I should have spent more time in the first place reviewing the original PR. Thanks for your contribution :)

@ilopmar ilopmar changed the base branch from master to 2.6.x August 6, 2021 11:13
@ilopmar ilopmar merged commit 350f218 into 2.6.x Aug 6, 2021
@ilopmar ilopmar deleted the issue-361 branch August 6, 2021 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate operationId values

2 participants