-
Notifications
You must be signed in to change notification settings - Fork 214
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
Compilation Error: java.util.Map
needs to be fully qualified when domain class is called Map
#5135
Comments
Hi @NetzwergX |
@baywet Thanks for pointing out the reserved names list. I am willing to provide a PR if I have a sufficient understand of what is going on. What exactly is the effect of adding the class, e.g. |
Not exactly, the result is that name cannot be used anymore for generated symbols (class names, enum names, enum members....). |
I wonder if thats the desired solution when we look at where this converges. There are several dozens of imports declared in the generated code files.
The last point is also a problem for evolution overall and applies to the reserved classes list in general. Say today I generate a client that uses a name as domain object class name that ends up being on the reserved names list in some future version. This would make all code generated in the future, where that class name is escaped incompatible with the current code. So overall, it seems a more robust solution would be highly desirable. And that is actually possible without too much effort. There are in general two approaches that can be used.
From a robustness perspective, especially wrt. forwards- and backwards compatibility (of the generated api and model), it seems to me that dealing with this on the side of the source generator and by disambiguating the class names while generating is the preferable option. It also ensures that future evolution of the generated code does not require synced changes in the reserved words list, making changes less error-prone. Personally, I'd go with just using FQNs everywhere when referring to types. Its the simplest to implement, offers all the advantages (robustness, forward- and backward compatibility both wrt. the generated source and evolution of the generated code) and has the only drawback of being more verbose on the source level. Let me know what your thoughts are on this topic. |
Thank you for the additional information. We've been through this topic with dotnet #5020, #4796 and many more. The solution depends a lot on the internals of the compiler. FQNs often seems like a more favorable approach until you start having symbol names that match namespace segments... The easiest to implement solution, with the least impact to existing clients that would potentially be refreshed, is the reserved names approach. We can always adjust later on based on people's feedback. From looking at this list here are the types that would need to be added f not already present:
We're talking about ~30 reserved names, and we're not expecting this list to grow by much in the future. Let us know if you have any additional comments or questions. |
authored #5184 |
If the domain class for an endpoint is called
Map
(see above), the compilation fails due to the clash with the importjava.util.Map
. In those cases, the generated code is trivially fixed by removing the import and fully qualifying all instances whereMap
refers tojava.util.Map
:Swagger config to try this out:
sovereignty/map
endpoint)The text was updated successfully, but these errors were encountered: