OpenAPITools / OpenAPITools/openapi-generator

[BUG][Kotlin] "date-time" type integrity violated when using default dateLibrary (java8)

Open
#20,078 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Description

When generating the domain model using default configuration of dateLibrary (=java8 according to https://openapi-generator.tech/docs/generators/kotlin/) the generated date-time objects are represented by java.time.OffsetDateTime.
These objects are evaluated to strings that look like this:

2024-11-08T06:54:06.831187+01:00

Date times should follow the format of RFC 3339 according to https://swagger.io/docs/specification/v3_0/data-models/data-types/#strings

In other words they should look like this:

2017-07-21T17:32:28Z

Workaround: Specify another date library, such as kotlinx-datetime which represents date-times with kotlinx.datetime.Instant

openapi-generator version

7.9.0

OpenAPI declaration file content or url
        foo:
          type: string
          format: 'date-time'
          description: Example
Generation Details

Generated using Gradle plugin

Steps to reproduce
gradlew openApiGenerate
Related issues/PRs
Suggest a fix

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running gradlew openApiGenerate with the shown OpenAPI declaration and inspect the generated Kotlin domain model and its date-time handling. Trace how the default java8 date library represents and serializes date-time values. Done means generated values follow the stated RFC 3339 form without requiring the kotlinx-datetime workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, kotlin
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.