https://kotlinlang.org logo
Title
r

Richard Gomez

08/20/2021, 7:01 PM
Is it possible to create 'helper functions' to instantiate annotations from 3rd-party libraries? I'm using SpringDoc to define OpenAPI metadata, and would like to remove visual clutter. e.g., something like this; this doesn't work because `Annotation class cannot be instantiated`:
fun apiResponseOf(code: Int, kclass: KClass<*>) = ApiResponse(responseCode = code.toString(), content = arrayOf(Content(schema = Schema(kclass))))

@Operation(summary = "List all Foos")
@ApiResponses(
    apiResponseOf(200, FooResponse::class)
)
Instead of:
@Operation(summary = "List all Foos")
@ApiResponses(
    ApiResponse(responseCode = "200", content = [Content(schema = Schema(implementation = FooResponse::class))])
)
y

Youssef Shoaib [MOD]

08/20/2021, 7:49 PM
r

Richard Gomez

08/20/2021, 7:58 PM
Neat, thanks.