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.
Make sure to use Membrane version 5 or newer.
-
Go to the
examples/openapi/validation
directory -
Start Membrane with the script inside this directory:
./membrane.sh
or:
service.proxy.bat
- 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.
- 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>
-
Incoming requests are validated against the definitions in the OpenAPI specification. In case of a validation failure an error message is returned.
-
The request is sent to the backend server with the server url from the OpenAPI definition:
info:
...
servers:
- url: http://localhost:3000
-
The answer is returned to the client.
-
You can also switch on response validation and check that the answer from the server is valid too.
validateResponses="true"
See:
- openapi reference