1
我有要求使用可選的路徑參數。所以就像下面那樣;修改SwaggerUI以刪除所需的PathParam
@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;
}
但隨着招搖,它不允許提出請求,如PathVariables
是required
型。我不知道多少JavaScript。試過this解決方案修改swagger-ui.js
,但似乎迷失在大文件中,並找不到提到的部分。
我使用最新的Swagger-UI版本。是否有可能我可以使用可選的路徑變量進行請求,正確的路徑應該顯示在大搖大擺?
注意:我知道swagger spec不允許可選的路徑變量。但是我只想在我的應用程序中更改它。
謝謝。