我在 swagger-ui 中生成的输出是:
DocumentChangeSet {
deletes (Collection«DocumentKey», optional),
updates (Collection«AbstractDocument», optional)
}
Collection«DocumentKey» {}
Collection«AbstractDocument» {}
有什么办法可以让它更详细
删除(集合«DocumentKey»,可选),
和
更新(集合«AbstractDocument»,可选)
给出每个部分的完整分解?
我的摘要如下:
@Bean
public Docket api(){
return new Docket(DocumentationType.SWAGGER_2)
.select()
.apis(RequestHandlerSelectors.any())
.paths(PathSelectors.any())
.build()
.genericModelSubstitutes(DeferredResult.class)
.alternateTypeRules(
newRule(typeResolver.resolve(DeferredResult.class,
typeResolver.resolve(DeferredResult.class,DocumentChangeSet.class)),
DocumentChangeSet.class)
)
.pathMapping("/")
.apiInfo(apiInfo());
}
要添加更多详细信息,请对 documentKey 和abstractDocument 进行注释。
下面是没有任何注释的 DocumentChangeSet 类。
public DocumentChangeSet(Collection<? extends AbstractDocument> updates, Collection<DocumentKey> deletes) {
this.updates = ImmutableSet.copyOf(updates);
this.deletes = ImmutableSet.copyOf(deletes);
}
@Override
public String toString() {
return Objects.toStringHelper(this)
.add("updates", updates.size())
.add("deletes", deletes.size())
.toString();
}
public Collection<AbstractDocument> getUpdates() {
return updates;
}
public Collection<DocumentKey> getDeletes() {
return deletes;
}
最佳答案
swagger 的工作方式是,它扫描 REST API 代码中的注释(这些注释可能是特定的 Swagger annotations 或 JAX-RS annotations ,甚至 Jackson annotations )并从中生成 JSON。
然后将此 swagger.json
提供给 Swagger UI,并为您生成漂亮的 UI 页面。
长答案短,需要使用注释。
关于java - SpringFox swagger-ui 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38010126/