-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Where there are multiple fields with same generic definition Map<K, V> (e.g Map<String, String>) then only the first field is rendered in the example text #2972
Comments
I have been dealing with this issue for the better part of a week and finally managed to nail down the root. The issue begins at line 613 of ModelResolver:
ModelConverterContextImpl (line 77) returns a cached Schema instance if it has already been processed:
ModelResolver at line 666 changes the name of that instance and adds it to the list of properties:
If you use a debugger and inspect props after this line, you can see that it actually contains multiple Schema instances--each with the name of the most recently parsed field. Then at line 674, each instance gets added to modelProps :
And of course, since they have all been assigned the same name, this results in only the final one being retained in the map. I changed ModelConverterContextImpl to return a clone of the cached instance, and it now includes all fields:
I will refine this code to only do the cloning when the AnnotatedType is of a Map and do some more testing, and can then create a PR if no other issues arise. |
…me generic definition
Hi, |
ref #2972 - fixes resolving multiple map properties
My pleasure; thanks to the entire community for building something so useful! It's a privilege to be able to give something back! |
Where there are multiple fields with same generic definition Map<K, V> (e.g Map<String, String>) then only the first field is rendered in the example text
When I have a response class with more than one field of type Map<String, String> only the first field will render
in the 'Example Value' part of the response definition in swagger ui
Only the below is output
However I can see the below lines being output to the log twice.
io.swagger.v3.core.converter.ModelConverterContextImpl resolve: resolve [map type; class java.util.Map, [simple type, class java.lang.String] -> [simple type, class java.lang.String]]
The text was updated successfully, but these errors were encountered: