OpenAPITools / OpenAPITools/openapi-generator
[REQ] Kotlin sealed classes support
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
Hello,
It would be great to enable support of Kotlin sealed classes. Is it going to happen? As far I know, there is no way to do it with the current version of OAI.
Describe the solution you'd like
Kotlinx Serializer now supports sealed classes. So, from:
@Serializable
sealed class OperationErrorV1 {
@Serializable
data class InvalidField(val field: String, val value: String?): OperationErrorV1()
@Serializable
data class NotFound(val title: String, val description: String): OperationErrorV1()
@Serializable
data class Conflict(val title: String, val description: String): OperationErrorV1()
@Serializable
data class Internal(val message: String): OperationErrorV1()
@Serializable
data class Unknown(val message: String): OperationErrorV1()
}
We can get smth like:
"errors": {
"type": "blablablaErrorV1.Operation",
"errors": [
{
"type": "blablabla.OperationErrorV1.InvalidField",
"field": "applicationId",
"value": null
},
{
"type": "blablabla.OperationErrorV1.InvalidField",
"field": "test",
"value": "test"
},
{
"type": "blablabla.OperationErrorV1.Internal",
"message": "hello"
}
]
}
Describe alternatives you've considered
Currently, I do generate default data classes from YAML. So, from smth like this:
OperationError:
title: OperationError
type: object
properties:
invalidField:
$ref: '#/components/schemas/OperationInvalidFieldError'
notFound:
$ref: '#/components/schemas/OperationNotFoundError'
conflict:
$ref: '#/components/schemas/OperationConflictError'
internal:
$ref: '#/components/schemas/OperationInternalError'
unknown:
$ref: '#/components/schemas/OperationUnknownError'
I receive the following data class:
@Serializable
sealed class OperationErrorV1 {
@Serializable
data class InvalidField(val field: String, val value: String?): OperationErrorV1()
@Serializable
data class NotFound(val title: String, val description: String): OperationErrorV1()
@Serializable
data class Conflict(val title: String, val description: String): OperationErrorV1()
@Serializable
data class Internal(val message: String): OperationErrorV1()
@Serializable
data class Unknown(val message: String): OperationErrorV1()
}
Additional context
OAI generator version - 5.1.1
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
The issue names no files, tests, or entry points. Start by locating the Kotlin generator's model-generation entry point and current tests for Kotlin data classes; done means supporting the demonstrated sealed-class hierarchy while preserving existing generation behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- kotlin
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100