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

[4.4.0] Schema Validation issue when sending invalid content type #3309

Closed
Ashi1993 opened this issue Oct 26, 2024 · 4 comments
Closed

[4.4.0] Schema Validation issue when sending invalid content type #3309

Ashi1993 opened this issue Oct 26, 2024 · 4 comments

Comments

@Ashi1993
Copy link

Description

When sending a request without a content type or with an invalid content type it gives an error correctly through schema validation. BUt the status code is 400. Ideally it should 415 because the content type is invalid.

{
    "code": "400",
    "message": "Bad Request",
    "description": "Schema validation failed in the Request: Request Content-Type header '[text/plain; charset=ISO-8859-1]' does not match any allowed types. Must be one of: [application/json; charset=utf-8]., "
}

Steps to Reproduce

Send a request with an invalid content type

Affected Component

APIM

Version

4.4.0-RC2

Environment Details (with versions)

No response

Relevant Log Output

No response

Related Issues

No response

Suggested Labels

No response

@NethmiRanasinghe
Copy link

This issue could be reproduced. Receiving a 400 Bad Request status code is the default behaviour for schema validation.

But, when schema validation is disabled, it correctly responds with a 415 Unsupported Media Type error for requests with an invalid Content-Type header.

Because of this, there is a confusion whether the Content-Type header validation should occur before schema validation, resulting in a 415 Unsupported Media Type error being returned first, even when schema validation is enabled.

@NethmiRanasinghe
Copy link

Hi @Ashi1993 ,

When sending a request with an invalid or empty Content-Type header:

  • When schema validation is disabled, throws a 415 Unsupported Media Type error.

  • When schema validation is enabled, throws a 400 Bad Request error because content-type header validation happens as part of the schema validation process. This is the expected behaviour and changing the status code would alter this.

@Ashi1993
Copy link
Author

Hi Nethmi,

In the ideal scenario even the schema validation should return 415 because the content type header is invalid.

Regards,
Ashirwada

@NethmiRanasinghe NethmiRanasinghe removed their assignment Jan 24, 2025
@Ashi1993
Copy link
Author

Hi Nethmi,

As discussed we will consider this as the correct behaviour since this s returned from schema validation.

Regards,
Ashirwada

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

No branches or pull requests

4 participants