[BUG]Error generating java due to a default for a date
Created by: bscheller-iso
Description
I'm facing a problem using a date in openapi3 and generating java or spring code using openapigenerator 4.2.2 or 4.2.3-SNAPSHOT.
openapi-generator version
openapigenerator 4.2.2 or 4.2.3-SNAPSHOT
OpenAPI declaration file content or url
openapi: "3.0.0"
info:
version: 1.0.0
title: Date Test
servers:
- url: http://localhost:8000
paths:
/dateTest:
get:
description: ""
parameters:
- name: start_date
in: query
required: false
schema:
type: string
format: date
default: '2020-01-22'
responses:
'200':
description: TODO
content:
application/json:
schema:
$ref: '#/components/schemas/Response'
components:
schemas:
Response:
type: string
Command line used for generation
java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -i C:/dev/test.yaml -g java -o C:/Data/ExampleGen/TestDateJava
Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement
The fix looks fairly simple (see https://github.com/OpenAPITools/openapi-generator/blob/bf57a9960d628f6517f610df9f5f79d5f4c49b33/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java#L832). The problem is that your query parameter is a date but the default value condition doesn't handle format options for strings. It should have a check for date and date-time, then construct a value according to the instantiation type. To get past this exception temporarily, you could remove the default from the spec.