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
[Java] Support enums in query params #1347
Comments
This can be tricky. When parameters are passed and mapped directly to enums, any name mismatching will cause big issues on the server side, typically things that you would need to handle on your own unless you're using some Jackson features for deserializing into enum properties It is valid to expect, and probably worth keeping open and implementing, but it can have some negative side effects. |
@fehguy This is an issue I am running into as well. It is tricky, to be sure! I'm using the Feign library and have a template that generates a client that works with Feign. In Feign you can specify custom "expanders" (basically serializers) to convert an arbitrary object into an representation that is query-string safe. Currently it appears that the model built up by swagger-codegen ignores the enum information when building up a CodegenParameter instance. This is especially the case when the query parameter is an array of enums. It appears that all the data exposed by swagger is correctly recognized, but it is not attached to the CodegenParameter instance. For example, I have the following schema that describes a parameter: {
"collectionFormat": "multi",
"enum": [
"UNKNOWN",
"CUSTOMER",
"LEAD",
"PARTNER",
"COWORKER",
"PERSONAL",
"SYSTEM",
"VISITOR",
"ANONYMOUS",
"VENDOR"
],
"in": "query",
"items": {
"enum": [
"UNKNOWN",
"CUSTOMER",
"LEAD",
"PARTNER",
"COWORKER",
"PERSONAL",
"SYSTEM",
"VISITOR",
"ANONYMOUS",
"VENDOR"
],
"type": "string"
},
"name": "classifications",
"required": false,
"type": "array"
} Currently I just end up with the type as I'm not too familiar with the code, but I don't mind taking a stab at this - it might amount to simply attaching the data that swagger-codegen already finds, to the CodegenParameter object. This way we at least have access to the information. Let me know what you think; thanks! |
@wing328 Any thoughts on this? I could submit a PR for this too. I'll see if I can take a first pass at this sometime this week. |
This is a fix to support enums in query parameters. Enum-related information was not being stored on `CodegenParameter` previously; it is now. Test cases have been added to make sure that the enum information is being properly processed from the model.
This is a fix to support enums in query parameters. Enum-related information was not being stored on `CodegenParameter` previously; it is now. Test cases have been added to make sure that the enum information is being properly processed from the model.
Support for enums in query parameters (issue #1347)
@vivin sorry that I missed your message. Yes, please submit a PR if you've time and we'll review accordingly. |
Is it planned ? or canceled ? |
@devaxt I would suggest you to pull the latest master to give it a try if you've not done so as there's been a lot of enhancements to swagger codegen since March. If it's still an issue, please let us know with the details such as the code generated and what you actually expected. |
@MatanRubin seems like it's still not yet supported. If you want to contribute the enhancement, please file a PR. |
@wing328 Did that commit I made make it in? It looks like the templates will need to be changed to support this, correct? |
@vivin yes, the templates need to be changed. There's a PR for Spring. |
Which PR?? I'm interested in, can u link us the PR pls? |
see #3198 |
I think it's important to have some kind of solution to this for all languages, not just Java. Even if it means just putting the enumerated values into the documentation, there needs to be some way for the user to know the possible values of a parameter. |
In Java generation, enums are generated when they are part of a definition object but not when they are a direct method property.
For instance:
Generates "status" as a String not as an enum.
The text was updated successfully, but these errors were encountered: