We are trying to set up springfox:swagger-ui. However, when creating the restcontroller with a post method using a Value.Immutable interface, the example is showing {}
and the model is showing the interface name but nothing else.
I noticed that, when I used the Immutable class as the requestbody, the example is showing all its attributes.
I tried adding the subtypes (@ApiModel(subTypes = ImmutableInputLead.class))
and parent configuration (@ApiModel(parent = ImmutableInputLead.class))
on the interface, which didn't change anything
This is our immutable interface:
@Value.Immutable
@ApiModel
@JsonSerialize(as = ImmutableInputLead.class)
@JsonDeserialize(as = ImmutableInputLead.class)
public interface InputLead {
@Nullable
@ApiModelProperty(example = "request id")
String getRequestId();
@Valid
Contact getContact();
}
Our mapping:
@ApiOperation(value = "Create a new lead")
@PostMapping(value = "/")
@Validated
public ResponseEntity create(@Valid @RequestBody InputLead inputLead) throws URISyntaxException {
String leadId = leadService.create(inputLead);
ResourceRef leadResourceRef = resourceRefFactory.newResourceRef("/api/leads/" + leadId);
return ResponseEntity.created(new URI(leadResourceRef.getUrl())).build();
}
Our objectmapper:
@Bean
public ObjectMapper objectMapper() {
Jackson2ObjectMapperBuilder builder = new Jackson2ObjectMapperBuilder()
.indentOutput(true)
.dateFormat(new ISO8601DateFormat())
.serializationInclusion(JsonInclude.Include.NON_EMPTY);
ObjectMapper objectMapper = builder.build();
objectMapper.registerModule(new JodaModule());
objectMapper.registerModule(new GuavaModule());
objectMapper.registerModule(new MazdaValuesModule());
objectMapper.registerModule(new DateTimeJacksonModule());
return objectMapper;
}
Our swagger config:
@EnableSwagger2
@Configuration
public class SwaggerConfig {
@Bean
public Docket api() {
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.directModelSubstitute(LocalDate.class, String.class)
.directModelSubstitute(LocalTime.class, String.class)
.directModelSubstitute(LocalDateTime.class, String.class)
.apiInfo(apiInfo());
}
private ApiInfo apiInfo() {
return new ApiInfoBuilder().title("Lead capturing API").build();
}
}
I would expect the variables of the InputLead class to be showing in the example.
What am I doing wrong?