SwaggerUi REST 方法 - 方法产生和使用完全相同的 mime 类型

SwaggerUi REST methods - methods produces and consumes exactly the same mime-types

我正在尝试使用 swaggeUI 创建 REST 方法。

一种通过id搜索User,通过firstName搜索用户的方法,如下:

@Produces( { MediaType.APPLICATION_JSON } )
    @Path( "/{firstName}" )
    @GET
    @ApiOperation( value = "Find User by e-mail", notes = "Find User by e-mail", response = User.class )
    @ApiResponses( {
        @ApiResponse( code = 404, message = "User with such e-mail doesn't exists" )             
    } )
    public User getUserByFirstName( @ApiParam( value = "E-Mail address to lookup for", required = true ) @PathParam( "email" ) final String email ); 


@GET
    @Path("/{userId}")
    @Nullable
    @Produces(MediaType.APPLICATION_JSON)
    User getUserById(@Nonnull @PathParam("userId") Long userId);

构建代码时出现此错误:

Following issues have been detected: WARNING: A resource model has ambiguous (sub-)resource method for HTTP method GET and input mime-types as defined by"@Consumes" and "@Produces" annotations at Java methods User getUserByFirstName(java.lang.String) and public abstract User getUserById(java.lang.Long) at matching regular expression /([^/]+). These two methods produces and consumes exactly the same mime-types and therefore their invocation as a resource methods will always fail. WARNING: The (sub)resource method indexUsers in UserService contains empty path annotation.

我是 REST 的新手,我需要帮助来解决这个问题。

谢谢

尝试更改您的@Path 定义。它无法判断 Long 应该是数字还是字符串 {firstname} 可以是 Long。

尝试:

@Path("/name/{firstname}")
....
@Path("/id/{userid}")