Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ResponseHeader annotation not parsed? #2684

Closed
2 tasks done
watery opened this issue Sep 14, 2018 · 5 comments
Closed
2 tasks done

ResponseHeader annotation not parsed? #2684

watery opened this issue Sep 14, 2018 · 5 comments
Labels
Milestone

Comments

@watery
Copy link

watery commented Sep 14, 2018

  • 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?

@dilipkrish
Copy link
Member

It should work, I'll research. Thanks for linking to the right issues and searching the repository 👍

@watery
Copy link
Author

watery commented Sep 17, 2018

Thank you.

This is the docket configuration:

@Bean
public Docket docket() {
	return new Docket(DocumentationType.SWAGGER_2)
			.select()
			.apis(RequestHandlerSelectors.any())
			.paths(PathSelectors.any())
			.build()
			.apiInfo(new ApiInfoBuilder().description(""). /* ... */ .build())
			.tags( /* ... */ )
			.forCodeGeneration(true)
			.globalOperationParameters(
					Arrays.asList(
							new ParameterBuilder()
							/* ... */
							.build()
					)
			)
			.directModelSubstitute(GregorianCalendar.class, String.class)
			.useDefaultResponseMessages(false);
}

@tommyb82
Copy link

tommyb82 commented 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.

@chaveen
Copy link

chaveen commented Jul 10, 2020

FYI, this exists in SpringFox 3 as well.

@NicolasBlackburn76
Copy link

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants