krakenjs / swaggerize-express

Design-driven apis with swagger 2.0 and express.
Other
354 stars 81 forks source link

Unsupported content type validation error #128

Open nielssj opened 6 years ago

nielssj commented 6 years ago

Hey, I've been using swaggerize-express to deliver an API for over a year on a rapidly changing product with various frontend clients and developers coming and going. The number one enquiry I get is regarding a scenario where they have to make a POST/PATCH request with a body and made the mistake of not setting the Content-Type header correctly.

Due to the solid validation error responses generated by swaggerize-express based on my model definitions they can usually solve validation errors like these on their own. However, in the case of a bad Content-Type the validation error states that the body is missing or rather "<name-of-body-parameter>" is required. Since I have worked with this backend for a while I know to check the Content-Type, but to a new API consumer this is not obvious.

I have attempted to set the "consumes" attribute in my swagger file, but the error response remains unchanged. Is there any nice way to deliver a more accurate error message using the Swagger definition or will we have to put together some custom validation middleware checking the Content-Type?