When using the ktor plugin for generating openapi documentation it fails to resolve enum and instead resolves it as "object. It works for the response object.
I don’t understand why it correctly annotates the Predicate enum for the response but not for the type safe routing annotation with @Resource?
Thanks for any help!
documentation.yaml
/api/tags/{id}/relations:
get:
description: ""
parameters:
- name: "dimension"
in: "query"
required: false
schema:
type: "string"
- name: "id"
in: "path"
required: true
schema:
type: "string"
- name: "predicate"
in: "query"
required: true
schema:
type: "object"
responses:
"200":
description: "OK"
content:
'*/*':
schema:
$ref: "#/components/schemas/RelationResponse"
RelationResponse:
type: "object"
properties:
subjectId:
type: "string"
format: "uuid"
predicate:
type: "string"
enum:
- "SUBGENRE_OF"
- "INFLUENCED_BY"
- "FUSION_OF"
- "PARENT_OF"
Classes:
@Resource("/tags")
data class Tags(val dimension: String = "") {
@Resource("{id}")
data class Id(val parent: Tags = Tags(), val id: String) {
@Resource("/relations")
data class Relations(val parent: Id, val predicate: Relation.Predicate)
}
}
data class RelationResponse(
val subjectId: UUID,
val predicate: Relation.Predicate,
val objectId: UUID,
)
data class Relation(
val subjectId: UUID,
val predicate: Predicate,
val objectId: UUID,
) {
constructor(rs: ResultSet) :
this(
subjectId = rs.getString("subject_id").toUUID(),
predicate = safeEnumValueOf<Predicate>(rs.getString("predicate"))!!,
objectId = rs.getString("object_id").toUUID(),
)
enum class Predicate {
SUBGENRE_OF,
INFLUENCED_BY,
FUSION_OF,
PARENT_OF,
}
}
Controller:
get<Tags.Id.Relations> { tag ->
val id = tag.parent.id.toUUID()
val predicate = tag.predicate
call.respond(service.getTagRelations(id, predicate))
}