Showing results for 
Search instead for 
Did you mean: 

How to specify request headers for a post method

New Member

How to specify request headers for a post method

I have a method like the following in my spring boot based web service. I am trying to generate open api spec for the following using swagger core annotations. I would like to add all the acceptable headers to the spec file. I am wondering how to do that with annotations. 


@Produces({ MediaType.APPLICATION_JSON + ";charset=UTF-8" })
@Operation(description = "This is my api")
//1. overall Header annotations
Response post(@Context HttpHeaders headers, //2. header parameters
@Context UriInfo uriInfo,
@RequestBody MyRequest myRequest) {


I am wondering where to put the annotations to list the headers. Also how to list all the headers. I saw many examples of headers in ApiResponse, but i am trying to add request header.




New Contributor

Re: How to specify request headers for a post method

You can do the following in the @Operation annotation over your method

@Operation(description = "This is my api",
    parameters = {
    @Parameter(in = ParameterIn.HEADER,
        name = "X-Version",
        description = "The API Version",
        required = true,
        schema = @Schema(type = "string"))}

You can also specify more details to the @Parameter or @Schema annotations if required.

Checkout the last section of Operation documentation


The above annotation showed up this way in my app's documentation




New Here?
Join us and watch the welcome video:
Top Kudoed Authors