OpenAPITools / OpenAPITools/openapi-generator
[BUG][Kotlin] Schema with object named `Timestamp` does not compile
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When generator a client from a schema with a schema object named Timestamp invalid Kotlin code is generated.
data class java.sql.Timestamp (
/* Milliseconds since the Unix epoch */
@get:JsonProperty("epochMillis")
val epochMillis: kotlin.String
)
The generator seems to be blindly using java.sql.Timestamp as the {{classname}} in template rendering even though it is defined as a custom schema.
openapi-generator version
7.12
OpenAPI declaration file content or url
info:
title: OpenAPI definition
version: v0
paths: {}
openapi: 3.0.1
servers:
- url: http://localhost:8080
description: Generated server url
components:
schemas:
Timestamp:
type: object
required:
- epochMillis
properties:
epochMillis:
type: string
example: '1481899949606'
description: Milliseconds since the Unix epoch
description: A timestamp object representing a point on the ISO timeline in milliseconds since the Unix epoch.
Generation Details
generatorName: kotlin
library: jvm-okhttp4
additionalProperties:
groupId: jp.ne.paypay
useSpringBoot3: true
serializationLibrary: jackson
idea: true
Steps to reproduce
- Generate the schema above using the openapi-generator config above
chmod +x gradlew./gradlew compileKotlin
Related issues/PRs
Suggest a fix
The issue appears to be that the CodegenModel's classname is being set to java.sql.Timestamp even though it should not.
I believe the fix should probably prevent that implicate behavior if the model is defined in the components.schemas.
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 the provided OpenAPI schema and Kotlin generator configuration, then run ./gradlew compileKotlin on the generated project. Trace how the components.schemas object named Timestamp becomes the generated class name and verify that the generated Kotlin declaration uses a valid custom model name rather than java.sql.Timestamp.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, kotlin
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100