首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >为什么在swagger api请求中找不到响应部分? 404错误/这是jsp项目

为什么在swagger api请求中找不到响应部分? 404错误/这是jsp项目
EN

Stack Overflow用户
提问于 2021-07-07 21:39:29
回答 1查看 132关注 0票数 0

我构建了一个虚拟api,我想在swagger上测试它。swagger.json已成功生成并执行,以显示swagger UI。但是存在404错误,无法找到响应部分。我该如何解决这个问题呢?

这是内置的swagger UI。

这是代码。

代码语言:javascript
运行
复制
@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();
}

}

请告诉我你还需要什么来澄清这个错误。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-07-08 22:49:12

问题解决了!

我希望这个答案能对其他遭受这种麻烦的人有所帮助。:)

错误来自@Api定义部分。我应该已经在那部分定义了路径。这是更正后的代码。

代码语言:javascript
运行
复制
@Path("/oauth2")
@Service
@Api
public class className () {
    .....
    @GET
    @Path("/authorize")
    .....

}

正如您所看到的,@Api定义部分需要@Path注释。:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68287174

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档