Ask a Question

Swagger ObjectMapper Customization

StuartJensen
Occasional Visitor

Swagger ObjectMapper Customization

Should be a simple enough thing, but four days gone still no answer... so here I am.

I have a REST API for which I want to generate swagger.yaml WITHOUT nulls (i.e. Include.NON_NULL)

My servlet web.xml is configured to successfully call the Swagger endpoint located in: io.swagger.jaxrs.listing.BaseApiListingResource

 

@Path("/swagger.{type:json|yaml}")
public class ApiListingResource extends BaseApiListingResource {

@Context
ServletContext context;

@GET
@Produces({MediaType.APPLICATION_JSON, "application/yaml"})
@ApiOperation(value = "The swagger definition in either JSON or YAML", hidden = true)

 

All of this works, happy, I get the YAML or JSON.

 

So what is the problem: I cant get the JsonInclude.Include.NON_NULL applied to the correct ObjectMapper so I get 3/4 of the output as "xxxxxx" : null.

I see many online examples using Spring that show how to do this, but I do not use Spring..

I see many online examples using code Annotations that show how to do this, but I do not have any code where I could put annootations

I have a Bootstrap where I customize the Swagger base documant and then set it onto the ServletContext: context.setAttribute("swagger", swagger);

I have a Jersey config servlet (in web.xml) that uses an instance of: io.swagger.jersey.config.JerseyJaxrsConfig.

I have been scouring these two touch points (Bootstrap, JerseyJaxrsConfig) looking at source code, and so far nothing.

I can get it to work if I alter the swagger databind JAR (forcing NON_NULL) and rebuild, but not a good option.

This has to be easy guys, what am I missing? Do I override some static class? Create a provider and register is somewhere?

Thanks

0 REPLIES 0
cancel
Showing results for 
Search instead for 
Did you mean: