How can I document objects that I don't have ownership over?

142 views Asked by At

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

1

There are 1 answers

0
brianbro On BEST ANSWER

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.