[Kotlin][Spring] optional types for required=false without defaultValue#2487
[Kotlin][Spring] optional types for required=false without defaultValue#2487markus-wa wants to merge 4 commits intoOpenAPITools:masterfrom markus-wa:kotlin-spring-optional-params
Conversation
|
I'm personally not quite happy with this https://github.com/OpenAPITools/openapi-generator/pull/2487/files#diff-333e74d43089b01287cc3b8a0b0f6986R509 but I've put it as ready for review so we can gather feedback on it. I've noticed that the regression actually seems to be coming from some change that changed the default value of Unfortunately I can't find the change, the only things I found around that area seem to be from 2016 or earlier. |
It could be related to a change I made as I did fix default values in some other generators. My apologies in advance. Is it correct to say that the issue should be fix by changing the default value of defaultValue to (I'm aware of your workaround in https://github.com/OpenAPITools/openapi-generator/pull/2487/files#diff-333e74d43089b01287cc3b8a0b0f6986R509) |
|
Yeah changing it to
That would be great, would probably be much cleaner than this here 😄! |
|
@markus-wa I've filed #2513 to fix the default value. Please review when you've time. |
|
Closing in favour of #2513 |
PR checklist
./bin/to update Petstore sample so that CIs can verify the change. (For instance, only need to run./bin/{LANG}-petstore.sh,./bin/openapi3/{LANG}-petstore.shif updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in.\bin\windows\.master,. Default:3.4.x,4.0.xmaster.cc: @jimschubert (2017/09) @dr4ke616 (2018/08)
Description of the PR
This fixes a regression
introduced (presumeably) by #1107 / #1106The parameter types should only be non-nullable if they are either required or have a default value. Since
defaultValueis"null"(a string) by default, mustache treats it as a value (not-false or unset) the{{#defaultValue}}bla{{/defaultValue}}branch was alway hit, never{{^defaultValue}}.....This change follows a similar pattern of the C# generator which uses the helper property
isNullablefor this instead.It also fixes
Failed to convert value of type 'java.lang.String' to required type 'java.lang.Integer'; nested exception is java.lang.NumberFormatException: For input string: "null"if the optional parameter isn't provided in the request by removing thedefaultValueparameter if it's"null".