Testing OpenApi Spec File against Api Server URLs
05/26/2021, WedVerifying Apis
Upon creating a REST API and then documenting with OpenApi, the entire set of routes are defined and described properly when the proper care is taken. To ensure that the server provides an Api that matches up to the OpenApi specification JSON or YAML, testing will be required.
Although it can be done by writing out each of the test case by hand for each route, it can be cumbersome when there might be a large set of routes to go through, such that it would be more advantageous to automate the testing process.
Since the shape of the routes exhibit a well-defined pattern, Api testing can be automated. One way of doing this is to use property-based testing through the schemathesis library to automatically generate and run the test cases for you. By using schemathesis, one can gain the convenience of using a single CLI command to run the test suite for all routes.
For example, using schemathesis against the server Api from my previous post with the following
schemathesis run http://localhost:3000/api-json
yields the CLI output below