Kest

Search

Search the documentation

OpenAPI

Types and Parameters

Describe request and response models, with examples.

The reference reads your handlers' types at build time, so a correct model needs no annotations. Add them to make the documentation more useful to the people who read it: a description says what a field means, an example shows what a good value looks like.

data class CreateOrder(
    @ApiProperty("Product code", example = "\"A1\"") @NotBlank val sku: String,
    @ApiProperty("How many to buy", example = "2") @Min(1) val quantity: Int,
    @ApiProperty("Delivery notes") val note: String? = null,
)
 
@Post fun place(
    @ApiBody("The order to place", example = "{\"sku\":\"A1\",\"quantity\":2}") @Body order: CreateOrder,
    @ApiParam("Coupon code", example = "SPRING") @Query coupon: String?,
): Order = orders.place(order, coupon)
AnnotationOnAdds
@ApiProperty(description, example)a DTO propertytext and an example in the model. example is a JSON literal: a string is "\"A1\"", a number is "2"
@ApiParam(description, example)a path, query or header parametertext and an example (plain text)
@ApiBody(description, example)the handlertext and a full JSON example shown in the Try it panel

What is read from the types

In your codeIn the reference
val note: String?optional (nullable)
List<Item>, nested data classesarrays and nested models
enum classthe allowed values
@NotBlank, @Size(min, max), @Min, @Pattern, @EmailminLength, maxLength, minimum, pattern, format
a handler returning Page<T>the page model

Errors share one ErrorResponse shape. Nothing needs annotating for the reference to be correct.

Tips

  • Examples matter most on bodies: the Try-it panel starts from the example, so a good one lets a reader call the endpoint with one click.
  • Describe units and formats ("amount in cents", "ISO date"): that is what the types cannot say.
  • Keep descriptions short, one line.

Read more