Tegral icon indicating copy to clipboard operation
Tegral copied to clipboard

Simpler syntax for defining responses' schema

Open utybo opened this issue 1 year ago • 1 comments

Currently:

get("/hello") {
    respond(Greeting("You"))
} describe {
    summary = "Greet someone"
    200 response {
        json { schema<Greeting>(Greeting("Hi!")) }
    }
}

I think it would be possible to implement the invoke operator on the various valid types to allow the following syntax instead:

200 response {
    json<Greeting>(Greeting("Hi!"))
    (json or xml)<Greeting>(Greeting("Hi!"))
}

utybo avatar Mar 22 '23 23:03 utybo

This is not possible until Kotlin's context() feature lands, because otherwise this requires defining an inline extension function (because of reified generic types) in BodyDsl

utybo avatar Aug 13 '23 10:08 utybo