-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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][Spring] Optional query parameter of type array-string doesn't respect defaults #890
Labels
Comments
Thank you for the detailed issue report. Feel free to propose a pull request with the proposed change. Let us know if you need help. |
4 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Description
Using OAS 3, I have a query parameter defined as follows:
However after running the generator, my controller class has the following defined as
defaultValue
:When a request is made to the service with the optional parameter missing, Spring creates a new string list and adds
new ArrayList<>()
as the single element of the list, so the defaulted string becomes:List<String> sort = ["new ArrayList<>()"]
When I leave
required: false
but remove the default entry:Then the result is
But in this case, Spring does not create a default value (since none was specified), so sort becomes null in the controller:
List<String> sort = null
Spring MVC expects a String as default value, but if it's meant to be a list, it could be a comma delimited list as a string
"a"
or at the very least, an empty string (which is parsed as an empty list).openapi-generator version
3.2.2
OpenAPI declaration file content or url
Command line used for generation
Gradle task
Steps to reproduce
See description ^^
Related issues/PRs
None
Suggest a fix/enhancement
I've already deduced where this value is coming from:
AbstractJavaCodegen.toDefaultValue(Schema p) {...}
Perhaps a resolution could be to override
toDefaultValue(Schema p)
inSpringCodegen
to implement the necessary functionality, without having to worry about the implications on other types of code generators.The text was updated successfully, but these errors were encountered: