-
So I am a bit unsure whether this is a support request, bug report, or feature request. I have a REST DTO that looks as follows (in Kotlin): /**
* Defines a reference to a resource that should be retrieved as an input for the action.
*/
// Helps OpenAPI understand the different types of InputResourceReference
@Schema(
description = "Defines a reference to a resource that should be retrieved as an input for the action.",
oneOf = [InputResourceReference.Action::class, InputResourceReference.Assignment::class],
discriminatorProperty = "type",
discriminatorMapping = [
DiscriminatorMapping(value = "action", schema = InputResourceReference.Action::class),
DiscriminatorMapping(value = "assignment", schema = InputResourceReference.Assignment::class)
],
)
// Helps Jackson understand the different types of InputResourceReference
@JsonTypeInfo(
use = JsonTypeInfo.Id.NAME,
include = JsonTypeInfo.As.PROPERTY,
property = "type"
)
@JsonSubTypes(
JsonSubTypes.Type(value = InputResourceReference.Action::class, name = "action"),
JsonSubTypes.Type(value = InputResourceReference.Assignment::class, name = "assignment")
)
sealed class InputResourceReference {
/**
* A reference of a resource generated and outputted by another earlier action within a profile.
* E.g. The executable generated by the compile action as input for a testcase.
*
* @property stage The stage that contains the action that outputs the resource.
* @property job The job that contains the action that outputs the resource.
* @property action The action that outputs the resource.
* @property uri The URI of the to-be-retrieved resource that is outputted by the action.
*/
@NoArgConstructor
data class Action(
val stage: String,
val job: String,
val action: String,
val uri: URI,
): InputResourceReference()
/**
* A reference to a resource that is available globally within an assignment.
* These are for example files that should always be available within testcases, or the student submitted files.
*
* There are 2 available schemes for this resource URI:
* - `file` for resources that are directly loaded from MinIO. Zips will be available in the container as a ZIP file.
* - `zip` for resources that are loaded from MinIO and unzipped. The contents of the ZIP will be available in the container as individual files.
*
* @property uri The URI of the resource within MinIO.
*/
@NoArgConstructor
data class Assignment(
val uri: URI,
): InputResourceReference()
} This is basically an abstract class with 2 implementations. The way Jackson deals with this is that it adds a "type" property to the json serialization so that it knows which type it is. So a serialization would look like:
OpenAPI however generates examples like:
This doesn't add the I am not sure whether:
I was hoping that adding the "discriminatorProperty" and mapping would solve this issue. Thanks in advance for any help, I really appreciate it. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
/cc @EricWittmann (openapi), @Ladicek (smallrye), @MikeEdgar (openapi), @geoand (kotlin), @jmartisk (smallrye), @phillip-kruger (openapi,smallrye), @radcortez (smallrye) |
Beta Was this translation helpful? Give feedback.
-
@LarsSven you can try adding the property to the @Schema(
// ... other @Schema attributes here
properties = { @SchemaProperty(name = "type", implementation = String.class) }
) |
Beta Was this translation helpful? Give feedback.
@LarsSven you can try adding the property to the
@Schema
onInputResourceReference
with@SchemaProperty
and it will merge with the properties found on the sub-classes.