java swagger参数排序_java-Swagger参数文档

当前状态:

我的控制器中有两种方法可以根据传递的参数获取数据.编码:

@RestController

@RequestMapping("/samples")

public class SampleController {

@RequestMapping(value = "/{id}", params = {"cost"}, method = RequestMethod.GET)

public String getSamplesByIdAndCost(@PathVariable String id, @RequestParam(value = "cost") String cost) {

return "result";

}

@RequestMapping(value = "/{id}", params = {"cost", "size"}, method = RequestMethod.GET)

public String getSamplesByIdCostAndSize(@PathVariable String id, @RequestParam(value = "cost") String cost,

@RequestParam(value = "size") String size) {

return "ID : " + id + " / COST : " + cost + " / SIZE : " + size;

}

}

一切工作正常,但是草率的文档不是我期望的.

03dOC.png

tNjPE.png

有没有办法从请求网址中删除{?size,cost}?

这是我的证件信息:

@Bean

public Docket myApi() {

return new Docket(DocumentationType.SWAGGER_2)

.select()

.apis(RequestHandlerSelectors.any())

.paths(PathSelectors.any())

.build()

.pathMapping("/")

.directModelSubstitute(LocalDate.class,

String.class)

.genericModelSubstitutes(ResponseEntity.class)

.alternateTypeRules(

newRule(typeResolver.resolve(DeferredResult.class,

typeResolver.resolve(ResponseEntity.class, WildcardType.class)),

typeResolver.resolve(WildcardType.class)))

.useDefaultResponseMessages(false)

.globalResponseMessage(RequestMethod.GET,

newArrayList(new ResponseMessageBuilder()

.code(500)

.message("500 message")

.responseModel(new ModelRef("Error"))

.build()))

.enableUrlTemplating(true);

}

@Autowired

TypeResolver typeResolver;

@Bean

UiConfiguration uiConfig() {

return new UiConfiguration(

"validatorUrl",// url

"none", // docExpansion => none | list

"alpha", // apiSorter => alpha

"schema", // defaultModelRendering => schema

UiConfiguration.Constants.DEFAULT_SUBMIT_METHODS,

false, // enableJsonEditor => true | false

true); // showRequestHeaders => true | false

}

解决方法:

Swagger规范不支持基于查询字符串的同一路径的多个文档,因此swagger-ui也不支持.

通过设置enableUrlTemplating(true)启用的功能似乎是springfox中的一个孵化功能,但目前无法与swagger-ui一起使用.

相关讨论可以在这里找到:

现在看来,您要么不得不使用在swagger-ui中看起来很奇怪的路径,要么必须合并文档.

标签:springfox,spring-boot,swagger,java

来源: https://codeday.me/bug/20191026/1938481.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值