Skip to content

Latest commit

 

History

History

validation

Request & Response Validation against OpenAPI - Detailed Example

Membrane can validate requests and responses against OpenAPI descriptions. The specifications can be in YAML or JSON format on disk or reachable over the network.

For a basic example see the validation-simple folder.

Running the example

Make sure to use Membrane version 5 or newer.

  1. Go to the examples/openapi/validation directory

  2. Start Membrane with the script inside this directory:

./membrane.sh

or:

service.proxy.bat
  1. Send some valid and invalid requests.

a.) From the requests.http file using Visual Studio Code or IntelliJ

  • Open requests.http
  • Send some requests

b.) Using curl

Run the file curl-requests.sh or parts of it.

How it works

  1. In the proxies.xml configuration there is an api that reads the OpenAPI document and creates the API accordingly in Membrane.
<api port="2000">
    <spec location="contacts-xxl-api-v1.yml" validateRequests="true" validateResponses="false" validationDetails="true"/>
</api>
  1. Incoming requests are validated against the definitions in the OpenAPI specification. In case of a validation failure an error message is returned.

  2. The request is sent to the backend server with the server url from the OpenAPI definition:

info:
  ...
servers:
  - url: http://localhost:3000
  1. The answer is returned to the client.

  2. You can also switch on response validation and check that the answer from the server is valid too.

validateResponses="true"

See: