【问题标题】:Modifying SwaggerUI to remove required PathParam修改 SwaggerUI 以删除所需的 PathParam
【发布时间】:2016-01-14 04:14:49
【问题描述】:

我需要使用可选的路径参数。所以让它像下面这样;

@ApiOperation(httpMethod = "GET", value = "Get User Details With Optional Path Parameters", notes = "Output depends on values provided")
@ApiResponses(value = {
        @ApiResponse(code = 404, message = "We do not unserstand what you mean"),
        @ApiResponse(code = 400, message = "You are not requesting like a BOSS.") })
@RequestMapping(value = { "/getuser/userid/{userid}",
        "/getuser",
        "/getuser/userid/{userid}/alias/{alias}", "getuser/alias/{alias}" }, method = RequestMethod.GET, produces = {
        MediaType.APPLICATION_JSON_VALUE, MediaType.APPLICATION_XML_VALUE })
@ResponseStatus(HttpStatus.OK)
private UserSchema getUserDetails(
        @PathVariable Optional<String> userid,
        @PathVariable Optional<String> alias) {
    Users user = null;
    UserSchema returningSchema = buildDefaultSchema();
    if (alias.isPresent()) {
        //Get The Value
    } else {
        //Try Get Other Value and do stuff etc.
    }
    //Similar for userid

    try {
        //Get User Data From DB
        user = dao.getUserData(userid,alias);
        //Bind data to returning schema
    } catch (Exception ex) {
        Log.error(getClass().getName(), ex);
        returningSchema.setResponseText("Something is Wrong");
    } 
    return returningSchema;
}

但是使用 swagger,它不允许发出请求,因为 PathVariablesrequired 类型。我不太了解javascript。尝试this解决方案修改swagger-ui.js,但似乎迷失在巨大的文件中,找不到提到的部分。

我使用最新的 Swagger-UI 版本。我是否可以使用可选的路径变量发出请求,并且正确的路径应该以大摇大摆的形式显示?

注意:我知道 swagger 规范不允许可选的路径变量。但我只想在我的应用中更改它。

谢谢。

【问题讨论】:

    标签: spring-boot swagger swagger-ui swagger-2.0


    【解决方案1】:

    是的,你绝对可以 fork swagger-js 和 swagger-ui 来支持这一点。看看operation.js中的Operation.prototype.getMissingParams

    【讨论】:

      猜你喜欢
      • 2020-02-22
      • 1970-01-01
      • 1970-01-01
      • 2022-01-14
      • 2021-06-11
      • 1970-01-01
      • 2023-01-17
      • 2023-01-19
      • 1970-01-01
      相关资源
      最近更新 更多