swagger-api / swagger-inflector

Apache License 2.0
158 stars 85 forks source link

Payload validation skips application/json content when request contains charset parameter #450

Open lancekf opened 10 months ago

lancekf commented 10 months ago

Given payload validation is turned on for incoming requests and a requestBody defining content of application/json in the openapi spec When a request is made with a Content-Type of application/json; charset=utf-8 Expectation: Then the request is validated against the defined application/json content spec Actual: Then the request is not validated

This appears to be due to the request's content-type being used as a key for getting the appropriate media from the Content Map at: https://github.com/swagger-api/swagger-inflector/blob/afdbac64fc58f42f3b22c7187602b70231065fa0/src/main/java/io/swagger/oas/inflector/controllers/OpenAPIOperationController.java#L353

In this scenario, mediaType will be equal to application/json;charset=UTF-8 but content only has a mapping for application/json, thus media becomes null and validation is subsequently skipped.

Using swagger-inflector:2.0.8