我们正在尝试设置 springfox:swagger-ui。但是,当使用 Value.Immutable 接口使用 post 方法创建 restcontroller 时,示例正在显示{}
,模型显示接口名称,但没有其他内容。
我注意到,当我使用 Immutable 类作为 requestbody 时,该示例显示了它的所有属性。我尝试在界面上添加子类型(@ApiModel(subTypes = ImmutableInputLead.class))
和父配置(@ApiModel(parent = ImmutableInputLead.class))
,并没有改变任何东西
这是我们的不可变接口:
@Value.Immutable
@ApiModel
@JsonSerialize(as = ImmutableInputLead.class)
@JsonDeserialize(as = ImmutableInputLead.class)
public interface InputLead {
@Nullable
@ApiModelProperty(example = "request id")
String getRequestId();
@Valid
Contact getContact();
}
我们的映射:
@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();
}
我们的对象映射器:
@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;
}
我们的招摇配置:
@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();
}
}
我希望 InputLead 类的变量会显示在示例中。
我究竟做错了什么?