question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ResponseHeader annotation not parsed?

See original GitHub issue
  • What version of the library are you using? 2.9.2

What kind of issue is this?

  • Bug report.

Neither of X-Hello nor X-Hello-Bis headers are rendered in Swagger-UI from the following controller, while all the other details are correctly displayed:

@CrossOrigin(origins = "*", maxAge = 3600)
@Api(tags={ "Test ResponseHeader" })
@RestController
@RequestMapping(path="/response-header", produces="application/json")
public class ResponseHeaderController {
	
	@ApiResponse(
			code=200, message="OK",
			responseHeaders={
					@ResponseHeader(name="X-Hello-Bis", description="X-Hello-Bis header description", response=String.class)
			})
	@ApiOperation(
			responseHeaders={
					@ResponseHeader(name="X-Hello", description="X-Hello header description", response=String.class)
			},
			value="Get test for response header",
			nickname="responseHeader", notes="Notes 'bout test"
		)
	@GetMapping(path="", produces="text/plain")
	public String responseHeader(@ApiParam(hidden=true) HttpServletRequest req, @ApiParam(hidden=true) HttpServletResponse resp) {
		resp.addHeader("X-Hello", "Hello!");
		resp.addHeader("X-Hello-Bis", "Hallo!");
		return "Hi!";
	}
	
}

I found issues #937 and #1271 both closed, am I missing something in my code?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
tommyb82commented, Oct 4, 2018

I have just hit this exact problem too, springfox 2.9.2 + spring boot 2.0.5.RELEASE. Tried via both @ApiResponse and @ApiOperation as described above, no response header properties in the generated swagger document.

2reactions
NicolasBlackburn76commented, Oct 22, 2020

Does this fix apply for SpringFox 3? The description fields in ResponseHeader do not seem to be showing up in swagger.json anymore for me when I bumped the version from 2.9.2 to 3.0.0. I had to replace depreciated methods ResponseMethodBuilder -> ResponseBuilder and globalResponseMessage -> globalResponses

    @ApiResponses(value = [
        ApiResponse(code = 200, message = "Contents successfully returned", responseHeaders = [
             ResponseHeader(name="X-Hello-Bis", description="X-Hello-Bis header description", response=String::class)
        ]),
        ApiResponse(code = 404, message = "Upload could not be found", response = ControllerAdvice.ErrorResponse::class)
    ])
    @ApiOperation(value = "X-Hello", notes = "notes.")

docket configuration

        val responseMessages = listOf(
                ResponseBuilder()
                        .code("401")
                        .description("Unauthorized")
                        .build(),
                ResponseBuilder()
                        .code("403")
                        .description("Forbidden")
                        .build()
        )

        val docket = Docket(DocumentationType.SWAGGER_2)
                .apis(RequestHandlerSelectors.any())
                .forCodeGeneration(true)
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build()
                .directModelSubstitute(Resource::class.java, MultipartFile::class.java)
                .useDefaultResponseMessages(false)
                .globalResponses(HttpMethod.GET, responseMessages)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Set response header in Spring Boot - Stack Overflow
There are three ways to do this: Set the response for a specific controller, in the Controller class: @Controller @RequestMapping(value ...
Read more >
How to Set a Header on a Response with Spring 5 - Baeldung
In this quick tutorial, we'll explore the different ways of setting a header on a service response, either for non-reactive endpoints or ...
Read more >
ApiResponse (swagger-annotations 1.6.2 API) - Javadoc.io
This annotation is not used directly and will not be parsed by Swagger. It should be used within the ... public abstract ResponseHeader[]...
Read more >
Web on Servlet Stack - Spring
If an application context hierarchy is not required, applications can ... For example, invoking an annotated controller requires resolving annotations.
Read more >
29.2 Creating a RESTful Root Resource Class
The JAX-RS API uses Java programming language annotations to simplify the ... The JAX-RS runtime parses URI path templates the same way, whether...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found