Membrane API Gateway returns 500 Internal Server Error with the title OpenAPI message validation failed when response validation is on and the backend response does not conform to the OpenAPI document. The backend is to blame, not the client, and the client receives this error instead of the backend response.
The response contains the status 500 Internal Server Error, the title OpenAPI message validation failed, a validation field that lists the errors, the problem type https://membrane-api.io/problems/user/validation and a link to this page. The type user/validation means that a message did not pass validation. Because the error happens in the response flow, the status is always 500. In production mode, the title is replaced by Internal Server Error and the type is shortened to https://membrane-api.io/problems/user.
With validateResponses on, Membrane checks every backend response against the response definitions of the operation in the OpenAPI document: the status code, the content type and the body schema. This makes sure that clients only receive responses that match the published contract. See OpenAPI Configuration and Validation.
api:
port: 2000
openapi:
- location: fruitshop-api.yml
validateResponses: true
api:
port: 2000
openapi:
- location: fruitshop-api.yml
validateResponses: true
The backend returns a status that the operation does not describe, for example a 500 or 404 error response when the document only lists 200.
The backend returns a Content-Type that is not listed for the status, for example text/html instead of application/json.
The body lacks a required property, has a property with the wrong type or format, or contains properties the schema does not allow. This often happens after a backend change that was not reflected in the document.
validation field of the response. Each entry names the location of the error and the violated constraint.While you fix the mismatch, you can switch response validation off with validateResponses: false.
By default, Membrane runs in development mode and adds details to error responses that help you find the problem. In production mode, the link to this page is left out:
configuration:
production: trueconfiguration: production: true
Add the configuration document to your apis.yaml and separate it from the APIs with ---. The list of violations in the validation field is still sent in production mode, because it describes the message against the published API. To leave it out, set validationDetails: false on the openapi entry:
api:
port: 2000
openapi:
- location: fruitshop-api.yml
validateRequests: true
validationDetails: false
api:
port: 2000
openapi:
- location: fruitshop-api.yml
validateRequests: true
validationDetails: false
Configuration reference:
Tutorials with runnable examples:
Still stuck? See the troubleshooting guide or ask on GitHub Issues. For commercial support, contact info@predic8.de.