[英]Is there a way to define queryparams for all endpoints in javax.ws.rs?
I am trying to document an already existing application using javax.ws.rs annotations to define what headers (@HeaderParam) and parameters (@QueryParam) a specific endpoint needs.我正在尝试使用 javax.ws.rs 注释来记录一个已经存在的应用程序,以定义特定端点需要的标头 (@HeaderParam) 和参数 (@QueryParam)。 This information would them be used to generate a swagger page for the application.
此信息将用于为应用程序生成 swagger 页面。
public Response SampleFunction(@RequestBody(...),
@QueryParam(...),
@HeaderParam(...),
@HeaderParam(...),
@HeaderParam(...),
etc etc etc){
return doStuff()
}
I have identified a set of "@HeaderParam" which are required for all endpoints.我已经确定了一组所有端点都需要的“@HeaderParam”。 I need to know if there is any way for me to define the @HeaderParam only once and use that definition for all endpoints and, since this is an already existing application, I need to do this change without any major code refactorization.
我需要知道是否有任何方法可以让我只定义一次 @HeaderParam 并将该定义用于所有端点,并且由于这是一个已经存在的应用程序,我需要在不进行任何主要代码重构的情况下进行此更改。
We believe to have found a solution for this matter.我们相信已经找到了解决这个问题的方法。 By declaring the @HeaderParam globally they appear for all endpoints without having to repeat the declaration for each endpoint.
通过全局声明 @HeaderParam,它们出现在所有端点上,而不必为每个端点重复声明。 Something like this:
是这样的:
@Path("/")
public class myClass{
@HeaderParam("Parameter_one")
@Parameter(example = "example_one)
Type parameter_one
@HeaderParam("Parameter_two")
@Parameter(example = "example_two)
Type parameter_two
public Response SampleFunction(@RequestBody(...),
etc etc etc){
return doStuff()
}
}
In this particular case, Parameter_one and Parameter_two will become available on the Swagger page for all endpoints.在这种特殊情况下,Parameter_one 和 Parameter_two 将在所有端点的 Swagger 页面上可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.