Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #5086
Closed
Open
Issue created Jan 23, 2020 by Administrator@rootContributor

[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.

Assignee
Assign to
Time tracking