Hello guys, I'm trying to move openapi doc generat...
# ktor
s
Hello guys, I'm trying to move openapi doc generate from third support to official plugin I have a common resp Class:
CommonResponse<T>
and a common page vo:
PageResult<V>
so I declare it like this in
.describe{ response { HTTP...OK { $here } } }
:
schema = jsonSchema<CommonResponse<PageResult<ImagePageVO>>>()
but, when i see the openapi.json, all response of
PageResult<V>
with different generic class have the same schema inside i'm just a junior programmer, just a little bit thought myself, it the step in picture lost the class info inside? or did i do something wrong? happy to be replied!
b
Hey, this might be related to this issue. Could you try it with Ktor 3.4.2 (just released) and see if this resolves the issue?
s
i'm using 3.4.2 and kotlin 2.3.20 right now
b
hmm sounds problematic. Is the problem that it's pulling out schema for
PageResult
and using the first element type?
yes I can see the problem in a test now... looks like this will happen with custom generics nested >= 2 levels
I would recommend introducing some generic helper for your common response types that just avoids the second level for now, like
Copy code
inline fun <reified E: Any> Parameter.Builder.commonResponseSchema(): JsonSchema = JsonSchema(
    properties = mapOf(
        "data" to ReferenceOr.value(
            jsonSchema<E>()
        )
    ),
    required = listOf("data")
)
❤️ 1
s
tks for reply, i’ll try it later is this behavior expected?
oh, i saw the issue thread tks 4 help, what a nice community