swagger-ui: How to add a header-param request to every-api

Viewed 1549

I am new to quarkus and have a bit familiar with swagger-ui. I am able to add a @Parameter to the an endpoint like this:

@Parameter(in = ParameterIn.HEADER, required = true, name = "my-header-id")

But, I would like to add this param to every endpoint. How can I achieve this?

I am using quarkus-smallrye-openapi for the ui.

1 Answers

You can specify parameters on method or class level. If you define the param as class field, then it will be added to all methods of the corresponding endpoint:

@Path("/someendpoint")
public class MyEndpoint {
  
    @HeaderParam("my-header-id")
    @Parameter(name = "my-header-id")
    String myHeaderId;

    @GET
    public Response getAll() {return Response.ok().build()}

    @GET
    @Path("{id}")
    public Response someMethod(@PathParam("id") String id) {return Response.ok().build();}
}
Related