Documenting custom data mapping

Viewed 408

I have written a custom Jackson JsonSerializer to serialise my Money POJOs to something like:

{
"amountMinorUnits": 123,
"currency": "USD",
 }

However in the Swagger when a Response POJO references a Money pojo, the Swagger sees the original Money POJO and makes out the API uses that, and not the customer serialised version.

so if I have

class Person {
   Money salary;
   ...
}

How do I make clear what the Money JSON is?

Thanks

1 Answers

Use directModelSubstitute in your swagger config.

Example for spring boot app. just focus on swagger configuration:

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .directModelSubstitute(Response.class, ResponseSerializer.class)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();
    }
Related