OpenAPITools / OpenAPITools/openapi-generator
[BUG][KOTLIN][MULTIPLATFORM] Generated code requires @OptIn(kotlin.time.ExperimentalTime::class) after upgrading to kotlinx-datetime 0.7.1
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
Checklist
Provided minimal spec to reproduce the issue
Validated input with OpenAPI validator
Tested with latest master (7.14.0)
Searched for related issues/PRs
Description
When generating Kotlin multiplatform client code with dateLibrary=kotlinx-datetime, the generated classes produce errors if the project uses kotlinx-datetime:0.7.1.
The issue:
This declaration needs opt-in. Its usage must be marked with '@kotlin.time.ExperimentalTime' or '@OptIn(kotlin.time.ExperimentalTime::class)'
This happens because kotlinx-datetime introduced new APIs in 0.7.x that are annotated with @ExperimentalTime.
openapi-generator version
7.14.0
Generation Details
Gradle configuration:
openApiGenerate {
inputSpec.set("$rootDir/shared/openapi/api.yaml")
generatorName.set("kotlin")
library.set("multiplatform")
additionalProperties.set(
mapOf(
"dateLibrary" to "kotlinx-datetime"
)
)
}
Dependencies:
implementation("org.jetbrains.kotlinx:kotlinx-datetime:0.7.1")
Steps to reproduce
- Use the config above with OpenAPI Generator 7.14.0
- Set dependency to kotlinx-datetime:0.7.1
- Build the project → compilation fails with opt-in error messages
Actual Output
Generated models (e.g., LocalDateTime usage) require @OptIn(kotlin.time.ExperimentalTime::class) annotations.
Expected Output
Generated code should compile without requiring manual annotation.
Either:
Automatically add @OptIn(kotlin.time.ExperimentalTime::class) where needed, or
Provide an option to generate code compatible with stable kotlinx-datetime API.
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 by reproducing the Kotlin generator configuration with generatorName=kotlin, library=multiplatform, dateLibrary=kotlinx-datetime, and kotlinx-datetime:0.7.1. Inspect the generated LocalDateTime usages and determine which compatibility approach is intended. Done means the generated project compiles without requiring a manual ExperimentalTime opt-in.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100