All docs This doc
||
Skip to end of metadata
Go to start of metadata

The API schema based request and/or response validator validate requests and responses coming to the API Microgateway. This validator validates requests and responses based on the API schema that is defined in the API definition. You can enable request validation, response validation, or both request and response validation. Whenever a request comes to the API Microgateway that request should be validated against the OpenAPI definition file of the requested API. If the request is valid, it is directed to the backend. If the request is invalid, error code 422 is returned. Whenever a response comes from the backend that response is validated against the OpenAPI definition file of the requested API. If the response is valid, it is directed to the user and if the response is invalid, error code 500 is returned.

When validating requests/responses, the validator gets the payload of the request/response and compares it with the relevant model defined in the OpenAPI definition file of the API. If there are any conflicts, the validator will identify that the request/response is an invalid request/response.

Request validation

  • Sending a valid request

  • Sending an invalid request

           


Response validation

  • The backend sends a valid response
  • The backend sends an invalid response 

Enable the schema validation

  • To enable request validation:
    1. Navigate to the micro-gw.conf file.
    2. Change the value of enableRequestValidation to true (enableRequestValidation = true).
  • To enable the response validation:
    1. Navigate to the micro-gw.conf file.
    2. Change the value of enableResponseValidation to true (enableRsponsetValidation = true).


Sample - Request Validation

curl -k -X POST "https://localhost:9095/v2/1.0.0/order" -H "accept: application/json" -H "Content-Type: application/json" -H "Authorization: Bearer d3023b73-4746-3269-9585-8f2e3e56ae49" -d "{\"customerName\":\"string\", \"delivered\":true, \"address\":\"string\", \"pizzaType\":\"string\", \"creditCardNumber\":\"string\", \"quantity\":0, \"orderId\":44}"

{"fault":{"code":900915, "message":"Unprocessable entity", "description":"44 is not the type, string"}}

     

  • No labels