OpenAPITools / OpenAPITools/openapi-generator
[BUG] [JAVA | Spring] Dates are not annotated on param model
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
Date and datetime are correctly annotated in query params but when you use a model as query param the model date and datetime properties are not correctly annotated so it cannot recognize format.
openapi-generator version
openapi-generator-maven-plugin 4.2.2
OpenAPI declaration file content or url
openapi: 3.0.0
servers:
- url: 'localhost:8080'
info:
version: 1.0.0
title: OpenAPI Zoo
license:
name: Apache-2.0
url: 'https://www.apache.org/licenses/LICENSE-2.0.html'
paths:
/zebras:
get:
operationId: getZebras
parameters:
- in: query
name: limit
schema:
type: number
- $ref: '#/components/parameters/SearchParams'
components:
parameters:
SearchParams:
name: animalParams
description: Search animal grouped parameters
in: query
style: form
explode: true
schema:
$ref: '#/components/schemas/AnimalParams'
schemas:
AnimalParams:
type: object
properties:
born:
type: string
format: date
example: '2019-12-01'
lastSeen:
type: string
format: date-time
example: '2020-02-22T10:30:00.000'
status:
type: integer
enum: [0,1]
default: 0
name:
type: string
example: 'Marty'
age:
type: integer
example: 15
Command line used for generation
<configOptions>
<dateLibrary>java8-localdatetime</dateLibrary>
</configOptions>
Steps to reproduce
Use maven plugin to generate the api, will create a model file AnimalParams.java, that file will have all parameters, included date and date-time ones, but this two parameters won't be annotated with @DateTimeFormat so it will crash when reading query parameters.
Related issues/PRs
#2053
#5389
Suggest a fix
Working on a fix to add annotations on pojo template for Spring.
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
Reproduce the issue with openapi-generator-maven-plugin 4.2.2 using the provided OpenAPI declaration and java8-localdatetime configuration, then inspect the generated AnimalParams.java and the Spring POJO template mentioned in the suggested fix. Done means date and date-time model properties receive the required @DateTimeFormat annotations and query parameters are parsed without crashing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100