You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Related to: #13484
In Kotlin, when using discriminator property, the data/concrete classes don't implement the generated interface.
With the following openapi.yaml spec:
openapi: "3.0.3"
info:
title: MS Pet API
version: 1.0.0
description: De API for testing the discriminator in openapi
paths:
/api/projects:
get:
summary: get a pet
operationId: getPets
tags:
- pets
responses:
200:
description: Succes respons
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/PetResponse'
components:
schemas:
PetResponse:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
discriminator:
propertyName: petType
Cat:
type: object
# all other properties specific to a `Cat`
required:
- petType
properties:
catName:
type: string
petType:
type: string
Dog:
type: object
# all other properties specific to a `Dog`
required:
- petType
properties:
bark:
type: string
petType:
type: string
Generates the following classes and interface in Kotlin:
interface PetResponse {
@Json(name = "petType")
val petType: kotlin.String
@Json(name = "catName")
val catName: kotlin.String?
@Json(name = "bark")
val bark: kotlin.String?
}
data class Cat (
@Json(name = "petType")
val petType: kotlin.String,
@Json(name = "catName")
val catName: kotlin.String? = null
)
data class Dog (
@Json(name = "petType")
val petType: kotlin.String,
@Json(name = "bark")
val bark: kotlin.String? = null
)
As seen, the data classes (Dog and Cat) don't implement the interface PetResponse, even when using the following property config:
additionalProperties.set(
mapOf(
"useOneOfInterfaces" to "true",
),
)
luismospinam
changed the title
[BUG] [Kotlin] when using discriminator pattern the Kotlin generator the data classes don't implement the Interface
[BUG] [Kotlin] when using discriminator pattern in Kotlin generator the data classes don't implement the Interface
Oct 30, 2024
Description
Related to: #13484
In Kotlin, when using discriminator property, the data/concrete classes don't implement the generated interface.
With the following openapi.yaml spec:
Generates the following classes and interface in Kotlin:
As seen, the data classes (Dog and Cat) don't implement the interface PetResponse, even when using the following property config:
Here's a simple project to demonstrate the issue: https://github.com/luismospinam/Openapi-generator-kotlin-discriminator
run ./gradlew openApiGenerate
The text was updated successfully, but these errors were encountered: