java - 为什么在 swagger api 请求中找不到响应部分?404错误/这是jsp项目
问题描述
我构建了一个虚拟 api,我想大摇大摆地测试它。swagger.json 已成功生成并执行以显示 swagger UI。但是有找不到响应部分的404错误。我该如何解决这个问题?
这就是代码。
@Service
@Api
public class className () {
@GET
@Path("/oauth2/authorize")
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@ApiOperation(value = "Authorization Grant", notes = "Authorization Grant")
@ApiResponses(value = {
@ApiResponse(code = 200, message = "Successfully Granted the Authorization"),
@ApiResponse(code = 400, message = "Missing or invalid request body"),
@ApiResponse(code = 403, message = "Forbidden"),
@ApiResponse(code = 404, message = "Schema not found"),
@ApiResponse(code = 500, message = "Internal error")})
public Response authorizationGrant(
@HeaderParam("X-AUTH-TOKEN") final String token,
@HeaderParam("X-CSRF-TOKEN") final String csrftoken,
@ApiParam(value = "Client ID", required = true) @QueryParam("Client ID") final String clientId,
@ApiParam(value = "Scope", required = true) @QueryParam("Scope") final String scope,
@ApiParam(value = "Redirect Uri", required = true) @QueryParam("Redirect Uri") final String redirectUri,
@ApiParam(value = "Response Type", required = true) @QueryParam("Response Type") final String responseType ) throws AccessDeniedException {
return Response
.status(Response.Status.OK)
.entity("{\"hello\": \"This is a JSON response\"}")
.type(MediaType.APPLICATION_JSON)
.build();
}
}
请告诉我您需要更多了解此错误。
解决方案
问题解决了!!!
我希望这个答案可以帮助其他遭受这种麻烦的人。:)
错误来自@Api 定义部分。我应该定义那部分的路径。这是更正后的代码。
@Path("/oauth2")
@Service
@Api
public class className () {
.....
@GET
@Path("/authorize")
.....
}
如您所见,@Api 定义部分需要@Path 注释。:)
推荐阅读
- amazon-web-services - 使用 Amazon PA-API 5.0 的高分辨率图像
- html - Svelte 3 为什么没有正确应用该类
- java - 带有 Swagger 3 的弹簧上下文索引器
- python - Discord.py 从其他文件导入命令总是失败
- wifi - 带有 wpa2-enterprise 和 wpa_supplicant 的静态 IP
- ios - 添加新条目后 UITableView 不会刷新
- flutter - 从 url Flutter 下载图片
- amazon-web-services - 使用 S3 作为触发器的 AWS Codepipelines。仅支持 zip 吗?
- bash - 在 shell 脚本中提示时如何提供密码
- ios - 如何在 iOS 14 的模块化架构中为 Firebase 收集 IDFA