OpenAPI
Operations
Group, name and describe endpoints.
An operation is one endpoint (POST /orders). By default Kest groups endpoints by controller and names them from the method; these annotations let you improve both.
| Annotation | On | Adds |
|---|---|---|
@ApiTag(name, description) | controller | the section of the sidebar (default: the class name without "Controller") |
@ApiOperation(summary, description, deprecated) | handler | a title and text; a KDoc comment on the handler is used when there is none |
@ApiResponse(status, description, type) | handler | another documented response (repeatable); type is the body (Unit::class for none) |
@Controller("/orders") @ApiTag("Orders", "Place and track orders")
class OrdersController {
/** Looks an order up by id. */ // a KDoc comment: its first sentence is the summary
@Get("/{id}") fun find(@Param id: String): Order = ...
@ApiOperation("Place an order", "Reserves stock and charges the card.")
@ApiResponse(409, "Out of stock", ErrorResponse::class)
@ApiResponse(402, "Payment declined")
@Post fun place(@Body order: CreateOrder): Order = ...
@ApiOperation("Cancel (old)", deprecated = true) @Delete("/{id}") fun cancel(@Param id: String) = ...
}Marking things deprecated
deprecated = true shows the operation struck through in the reference and flags it in the OpenAPI file, so client generators warn their users. Pair it with an API version and a removal date.
Responses
The success response is taken from the return type. List the other outcomes a client should handle (404, 409, 422) with @ApiResponse, so people know what to expect; a 401 is added for secured endpoints.
Open /docs for the site with a Try it panel on every endpoint, /docs/openapi.json for the OpenAPI 3 export.