OpenAPITools / OpenAPITools/openapi-generator
[BUG] Spring Boot fails to parse LocalDate path parameter
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
This is basically same issue as with https://github.com/OpenAPITools/openapi-generator/issues/2053 with the only difference that this occurres when using path instead of query parameter.
Server fails to parse LocalDate because format annotation is missing in the generated code.
openapi-generator version 4.3.1
OpenAPI declaration file content or url
/foo/{date}:
get:
parameters:
- name: "date"
in: "path"
required: true
schema:
type: string
format: date
example: 2020-01-15
responses:
200:
description: ""
content:
application/json:
schema:
type: string
produces
default ResponseEntity<String> fooDateGet(@ApiParam(value = "",required=true) @PathVariable("date") LocalDate date) {
}
causes error:
Failed to covert 2020-08-06 to type:java.time.LocalDate. Text '2020-08-06' could not be parsed at index 4
Related issues/PRs
Same issue as in https://github.com/OpenAPITools/openapi-generator/issues/2053 but for path parameters
Suggest a fix
Same fix from https://github.com/OpenAPITools/openapi-generator/issues/2053 to be applied to in: path parameters
should be
default ResponseEntity<String> fooDateGet(@ApiParam(value = "",required=true) @PathVariable("date") @org.springframework.format.annotation.DateTimeFormat(iso = org.springframework.format.annotation.DateTimeFormat.ISO.DATE) LocalDate date) {
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the provided OpenAPI declaration and generated Spring Boot method fooDateGet, then compare this path-parameter case with issue 2053. Reproduce the generated code and verify that the LocalDate path parameter includes the required date-format annotation and parses the example value successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100