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
Duplicate class names in different packages get squashed in ControllerDocumentation - modelMap #182
Comments
@mbazos Interesting bug and totally an overlooked case :) Thanks for pointing it out! 👍. Couple of observations, not to be pedantic and all :-o!
With that out of the way, there is certainly a case that has the notion of the model namespaced by package rather than by the name of the type, like in your case com.xxxxx.canonical.Pet and com.xxxxx.summary.Pet. I would say the simplest solution, (for now) rather than bringing in the package name etc. is the create a custom annotation. public void sampleMethod3(@ModelAlias("PetCanonical") com.xxxxxx.canonical.Pet petOne,
@ModelAlias("PetSummary") com.xxxxxx.summary.Pet petTwo) {
} I'd modify ResolvedTypes to handle aliasing model names. I think its fairly simple and also doesnt clutter the names with package names etc. I'm trying to get an intermediate release with 1.2 spec support, so, If you have some cycles I'd love to take in a pr! I'm planning to pay down some tech debt in 0.7 and modularizing the library. I could create a chore to make that an extensibility point. Let me know if you have any questions. |
Thanks for getting back to me so quickly with this. So I completely agree with you on the two points you have outlined. Based on what you are saying and it completely makes sense is that I would rename my objects that are similar to give them a more distinct name. For the example you outlined above you could have com.xxxxxx.canonical.Pet and com.xxxxxx.summary.PetSummary or com.xxxxxx.canonical.PetSummary. That way the domain objects are distinct and there is no confusion about what Pet domain object is what. The above annotation becomes valuable when you supporting multiple versions of a given service (happens all the time because consumers might not want to move to the latest...for whatever reason). Imagine this package structure:
I know ideally your canonical model shouldn't change but in practice this happens I see these things happen:
Service versioning is always an interesting topic. Again I really appreciate the help. |
I have a similar situation except that this is happening on the response class as well. Example below:
The Swagger docs will only contain one representation of |
Yeah this needs to be fixed. |
I'm also having the same issue. A fix would be very much appreciated! |
If I have some time I might work on this. I recently upgraded our apps from swagger-springmvc to springfox and I am really liking the re-organization and re-packaging of the libraries. I am going to be out of the country and won't be back until the last week in September, I will make sure to check here before I start any work on this. |
@mbazos 🤘 would be much appreciated! However, since this feature affects the core, I would like to collaborate on how you plan to approach this before you work on the PR. Just want to make sure its in-line with the direction we want to take this library. Let me know if I can answer any questions. |
Could you please provide some aprox estimations when the issue will be fixed? |
ping @mbazos! |
Yes been very busy with life and work. Currently on break for the holidays will try to get this done before the new year. |
Not a problem... was just pinging to see if you still had plans to help with this feature. It will be much appreciated ... Thanks! |
@dilipkrish It's been a while since I have looked at this code and our discussion above references the old version of swagger-springmvc before you worked on the major refactor. Anyway I forked the repo and got my local workstation all up and running. Just wanted to check a few things: Also I took a second look and I can see in the DefaultModelProvider the following:
I believe .id() needs to be the fully qualified name but .name() needs to be the simple name. Can you just let me know to make sure I am on the right path. |
I believe thats sounds correct but haven't dug in recently to tell u without spelunking. Off hand I know that there is also TypeNameExtractor that uses the TypeNameProviders plugins. I thought I'd just chime in with a few expectations.
I'll report back if I find anything different or interesting. Thanks for helping out! |
@dilipkrish just getting comfortable with the project and I have to be honest, I am trying to setup the things you mentioned above and I am partially there but I am having a hard time understanding how everything is connected. I think I know the code changes I need to make in DefaultModelProvider but I am having a hard time understanding what I need to do to setup the plugin so I can make the decision of when to use this new behavior or not. I am a little confused about the operation/unique ids examples you sent me. is there an irc chat or something that some of the devs use? |
… wth generating swagger docs. See issue springfox/springfox#182 - where the package is ignored for classes with the same name, which caused /api/bookings/{bookingId} to incorrectly show the alert structure for model/v1/Alert.java, not model/Alert.java.
… wth generating swagger docs. See issue springfox/springfox#182 - where the package is ignored for classes with the same name, which caused /api/bookings/{bookingId} to incorrectly show the alert structure for model/v1/Alert.java, not model/Alert.java. (#273)
@dilipkrish Why the ticket is marked as solved? What's the solution to use |
Sorry, saw it was marked as solved in the release notes but not in the actual ticket |
@robertsearle, @benjvoigt , the fix has been merged to master branch. Could you, please, provide a feedback for 3.0.0-SNAPSHOT, if the issue was fixed or not ? |
@MaksimOrlov numbering appears to be stable between runs now, ty. I tested with multiple endpoints and also with nested models as return value. |
* Create a FormParameter model object instead of BodyParameter for fields that are part of a multipart form (in=formData). * Adapted behavior of ParameterMapper and added tests. * Fix contract tests. * Reduce diff from master contract files. * Bump mixin-deep from 1.3.1 to 1.3.2 in /springfox-swagger-ui/src/web Bumps [mixin-deep](https://github.com/jonschlinkert/mixin-deep) from 1.3.1 to 1.3.2. - [Release notes](https://github.com/jonschlinkert/mixin-deep/releases) - [Commits](jonschlinkert/mixin-deep@1.3.1...1.3.2) Signed-off-by: dependabot[bot] <support@github.com> * [fix issue 3118] discriminator not set to discriminator from model * fix discriminator usage in test templates * springfox#182 Fix sort ordering. * springfox#182 Fix checkstyle. * springfox#182 Fix resource listing. * springfox#182 Fix Webflux tests. * Bump swagger-ui depdency Security fix detailed in swagger-ui's release notes. https://github.com/swagger-api/swagger-ui/releases/tag/v3.23.11 * Set the basePath using the request context path if present This allows the X-Forwarded-Prefix header to work correctly * Updated spring dependencies to spring 5.2.0 and spring boot 2.2.0, fixed changed interfaces * Added documentationType in DocPluginManager tests * Fixed typo (springfox#3161) * springfox#2932 - Removed trailing space * springfox#2932 - Spring HATEOAS 1.0.0.RELEASE * springfox#2932 - Spring Data REST 3.2.0.RELEASE * springfox#2932 - fix hateos collectionModel rule * Fixed checkstyle issues in ParameterMapper.java Signed-off-by: Martin Kremers <info@martinkremers.de> * More test cases for parameter Mapper spec Signed-off-by: Martin Kremers <info@martinkremers.de> * fix for issue springfox#3178 replace new FileInputStream(resource.getFile()) with springfox#3178 * reéoved unused import * added test for coverage * springfox#3189 - handle defaults in Spring placeholders * springfox#3189 - return default value if property not found in environment * springfox#2932: Fixed import for model test. * springfox#2932: Minor version upgrades of spring dependencies. Aligned contract tests with Spring HATEOAS 1.x. Fixed wrong client encoding used in tests. * jackson 2.10.1 * Bump handlebars from 4.1.2 to 4.5.3 in /springfox-swagger-ui/src/web Bumps [handlebars](https://github.com/wycats/handlebars.js) from 4.1.2 to 4.5.3. - [Release notes](https://github.com/wycats/handlebars.js/releases) - [Changelog](https://github.com/wycats/handlebars.js/blob/master/release-notes.md) - [Commits](handlebars-lang/handlebars.js@v4.1.2...v4.5.3) Signed-off-by: dependabot[bot] <support@github.com> * Update test to pass when running on Windows. * Upgrade to version of swagger which fixes css injection vulnerability as defined in https://github.com/tarantula-team/CSS-injection-in-Swagger-UI Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Stefan Bissell <26431980+weaselflink@users.noreply.github.com> Co-authored-by: Maksim Orlov <maksim.orlov@yahoo.fr> Co-authored-by: Steven Locke <StevenLocke@users.noreply.github.com> Co-authored-by: Jerry Collings <jcollings@ancestry.com> Co-authored-by: JoGir <JoGir@users.noreply.github.com> Co-authored-by: Andree Wormuth <wormuth@users.noreply.github.com> Co-authored-by: Martin Kremers <info@martinkremers.de> Co-authored-by: Olivier Gérardin <ogerardin@yahoo.com> Co-authored-by: Andreas Kluth <AndreasKl@users.noreply.github.com> Co-authored-by: sullis <github@seansullivan.com> Co-authored-by: Dilip Krishnan <dilipkrish@users.noreply.github.com>
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically closed because it has not had recent activity. Please re-open a new issue if this is still an issue. |
For java, you can use the following workaround @primary
} You can modify it if needed :) |
please refer the files in repo for the fix same class name issue fix in open api swagger it will generate schema request response as per java annotation naming convention against the java variables. it will not create schema request response as per java variables it will follow schema annotation |
@MaksimOrlov Just tried 3.0.0 and the issue is still not fixed. Maybe because in my case the difference is not a package name, but an outer class name:
And:
Only one |
This helped me:
|
This solution solved my problem the fastest. - com.example.domain.dto.foo.Foo.Create
- com.example.domain.dto.bar.Bar.Create
package com.example.domain.dto.foo
@ApiModel("FooCreate")
data class Create(){}
package com.example.domain.dto.bar
@ApiModel("BarCreate")
data class Create(){} |
@dilipkrish |
For newest swagger annotations this helps: @Schema(name = "CustomName") |
ten years passed 😭 |
I haven't yet made a fix for this yet but our team encountered this issue and I believe it's fairly easy to fix but wanted to get feedback from you on how to go about this.
Example of the issue given the following controller method:
Notice that petOne and petTwo are different classes but have the same class name. When the ControllerDocumnetation modelMap is being populated it uses a friendly class name as the key so it would be "Pet" in this instance. With "Pet" being the same key in the model map they will overwrite each other.
Ways I was thinking to go about fixing this:
I am really not sure which one to do...friendly names are nice but people might end up not realizing this is happening so it's almost safer to have fully qualified.
Not sure if you need a reason of why this is important but here is it:
Let me know what you think and if I have time I don't mind working on this fix as it will benefit our team.
The text was updated successfully, but these errors were encountered: