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

Content-Type header validation fails if the content type contains custom header values #91

Open
AtomicTroop opened this issue Aug 13, 2024 · 2 comments

Comments

@AtomicTroop
Copy link

A response with, for example, a Content-Type: application/json; version=2 header fails validation against a spec that defines that same type as a valid response type, like so:

... path and operation omitted ...
"responses": {
  "200": {
    "content": {
      "application/json; version=2": {
        "schema": { ... }
      }
    }
  }
}

The returned validation error:

Message: GET / 200 operation response content type 'application/json' does not exist
HowToFix: The content type is invalid, Use one of the 1 supported types for this operation: application/json; version=2

This seems to be happening because helpers.ExtractContentType() assumes Charset and Boundary as the only valid header values for Content-Type and discards everything else.

Further down the validation logic, on L72 of responseBodyValidator.ValidateResponseBodyWithPathItem(), this content type stripped to a media type is then being compared directly with the content types allowed by the specification. This will of course always fail if any additional header values are present in the spec.

@daveshanley
Copy link
Member

Please help me out and submit a PR! All are welcome, if you know how to fix it, please help!

@AtomicTroop
Copy link
Author

I'd be glad to submit a PR for this, will see if I can make time for it sometime in the near future.

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

2 participants