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

@Header annotation does not parse @Schema(implementation) #2965

Closed
timothybasanov opened this issue Sep 22, 2018 · 3 comments
Closed

@Header annotation does not parse @Schema(implementation) #2965

timothybasanov opened this issue Sep 22, 2018 · 3 comments
Assignees

Comments

@timothybasanov
Copy link

timothybasanov commented Sep 22, 2018

I've added something like this to my JAX-RS-based server:

 @ApiResponse(responseCode = "204",
      description = "Operation was successful",
      headers = @Header(name = Headers.EXAMPLE_HEADER,
          schema = @Schema(implementation = ExampleTypes.ExampleHeader.class))

Expected: To see this header in my openapi generated spec.
Actual: Swagger core ignored a header annotation

Additional details:

  • io.swagger.v3.oas.annotations.responses.ApiResponse#headers is seemingly only read from io.swagger.v3.jaxrs2.OperationParser#getApiResponses
  • It calls io.swagger.v3.core.util.AnnotationsUtils#getHeader which in turn does this:
if (header.schema() != null) {
            if (header.schema().implementation().equals(Void.class)) {
                AnnotationsUtils.getSchemaFromAnnotation(
  • Looks like if schema is specified, but it has implementation, then header is silently discarded

Recommended solutions (one of):

  • Ignore @Schema annotation entirely, but still add a header even if only a name is specified
  • Parse "implementation" part of header spec correctly
  • Throw exception when non-Void implementation is detected
  • Log when non-Void implementation is detected
@ans1genie
Copy link

Any updates when this bug will be fixed? any workaround?
I would like to see this suggestion from @timothybasanov previous comment:

Parse "implementation" part of header spec correctly

@ans1genie
Copy link

ans1genie commented May 22, 2023

A possible workaround, (it may not look clean 🤷🏻), is to implement the OperationCustomizer interface, intercept/find the header and then patch the schema programmatically.

@micryc
Copy link
Contributor

micryc commented Feb 1, 2024

Fixed by #4608

@micryc micryc closed this as completed Feb 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants