Duplicate model names don't throw but are overwritten
See original GitHub issueI’m using version 1.5.10 and experiencing the following issues: I have two classes with the same simple name but in different namespaces. When I generate my swagger file, one of them “wins” and overwrites the first one.
I’ve found a workaround to use a custom model name via ApiModel
. Alternatevly, I could make use of one of the other name resolvers like Jackson’s annotation.
But still, I’d like to detect such a name clash automatically and not by accident when the specs don’t match the API. What do you think about adding a check here? I can provide a PR if wanted, just wanted to talk about it before.
Alternatively, I’d have to execute the same class scanning as Swagger does in order to find such a clash.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:11
- Comments:12 (2 by maintainers)
Top Results From Across the Web
Duplicate Object and working with Duplicate without changing ...
In order to change one instance without changing the other you need to clone the actual values of this instance and not the...
Read more >How to Clone Objects with Mutable field in Java? Example ...
When we override the clone() method inside the Programmer class, we need to explicitly take care of this List, otherwise, both original and...
Read more >Things to Know About Duplicate Rules - Salesforce Help
Review considerations for using and customizing duplicate rules.
Read more >Object references and copying - The Modern JavaScript Tutorial
When an object variable is copied, the reference is copied, but the ... If the copied property name already exists, it gets overwritten:....
Read more >File.Copy Method (System.IO) - Microsoft Learn
Overwriting a file of the same name is not allowed. ... Message); } } // Delete source files that were copied. foreach (string...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Not sure this is helpful but I figured I’d add what worked for me.
Our use case is a Spring Boot application and we’re adding Swagger UI. Our controllers often times have inner classes for requests and responses, but are often generically named
Request
andResponse
, which causes conflicts due to how theDefaultTypeNameProvider
usestype.getSimpleName()
:https://github.com/springfox/springfox/blob/master/springfox-schema/src/main/java/springfox/documentation/schema/DefaultTypeNameProvider.java#L35
Our solution was to just create our own
TypeNameProviderPlugin
, which is a component on one of our@Configuration
sFound out about plugins via documentation here: https://springfox.github.io/springfox/docs/snapshot/#plugins
Hope this helps someone! 🤞
+100 This is a huge issue for us. We have hundreds of APIs and add more every month. The fact that swagger silently overwrites models if they have duplicate names has caused a lot of issues; most importantly of which is that we cannot trust the swagger documentation. It would be nice if the scanner would at least log when it finds a duplicate api model.
Keep in mind this is only manifests itself if you have two models with the same value but have different structures. In our case, we had many models with duplicate values, but the structures were the same. However, for many models with the same value, the models were similar but not identical, which caused further confusion since things looks mostly correct.
For those struggling with this, our solution was to write our own annotation scanner and search for apimodel annotations with a duplicate value, then going into the code and manually making them unique. We are working this process into our pre-promote workflow. But it would be better if the tool didn’t allow this to happen in the first place.