3

I'm returning a Page<SomeObject> In my method endpoints. In my OpenAPI UI, how can I generate a description of the fields that come from org.springframework.data.domain.Page type. Normally what I do is go to the Object that I want to document and annotate its fields with @Schema(description = "some description"). But I don't have access to the Page class. How can I document its fields?

I'm probably missing something simple here, but any help would be appreciated.

PS: I am using OpenAPI v3 and springdoc

Hamza Belmellouki
  • 2,516
  • 1
  • 18
  • 39

1 Answers1

1

You can use OpenApiCustomiser.

Let's say for example you have this controller:

@RestController public class HelloController {

@GetMapping("/hello")
Page<PersonDTO> getPage() {
    return null;
}

}

Let's suppose you want add the description the Pageable element:

@Bean
public OpenApiCustomiser pageableOpenApiCustomiser() {
    return openApi -> {
        Schema pageableSchema = openApi.getComponents().getSchemas().get("Pageable");
        pageableSchema.setDescription("my description");
    };
}

The same logic applies for any other attribute you nned to customize.

brianbro
  • 4,141
  • 2
  • 24
  • 37