Viktor Baert
Viktor Baert

Reputation: 798

How to set description to a field using swagger OpenAPI annotations

To improve our api documentation I want to add a description to a field of a response body

as an example see the default petstore spec here: https://editor.swagger.io/

In the POST /pet in the pet response, status has the description "pet status in the store"

How can I do this from an annotation perspective in my code base?

(swagger v3)

Upvotes: 9

Views: 15040

Answers (2)

Viktor Baert
Viktor Baert

Reputation: 798

Solution in Kotlin:

data class Pet(
       @field:Schema(description = "Pet status in the store")
       val status: String
    )

Upvotes: 12

Dennis Gloss
Dennis Gloss

Reputation: 2841

import io.swagger.v3.oas.annotations.media.Schema;

public class Pet {
    @Schema(description = "Pet status in the store")
    private String status;
}

thanks @viktor-baert

Upvotes: 16

Related Questions