Schemathesis generates and executes property-based tests from an API definition, avoiding hand-written tests for every endpoint and response type. It exercises happy and sad paths against an API gateway or service while checking whether responses conform to the published schema. section 7.4 section 7.4.1
Listing 7.3 Running Schemathesis
st run #1 --checks all #2 --contrib-openapi-formats-uuid #3 --cassette-path cassette.yaml #4 --data-generation-method all #5 --base-url http://localhost:8000 #6 --header "X-API-Key: my_secret_api_key" #7 product-catalog-v1-0.oas.yaml #8
Run the Schemathesis CLI with all checks, broad data generation, a base URL, authentication, cassette recording, and the OpenAPI definition. section 7.4.1
A typical workflow includes:
- Start the API gateway and API service that will receive generated requests. section 7.4.1
- Run the CLI against the OpenAPI definition, selecting checks, data-generation methods, a base URL, and required headers. section 7.4.1
- Record requests in a cassette file so generated traffic can be inspected and retained. section 7.4.1
- Use examples in the OpenAPI document deliberately: Schemathesis can send those values, making realistic examples useful for both documentation consumers and automated testing. section 7.4.1
Finding a product-catalog schema defect
Against a product-catalog API, Schemathesis used the documented productId UUID and produced a failing response-schema check: additional properties numberOfReviews and reviewRating were not allowed. A summary can distinguish successful checks for server errors, status codes, content types, headers, and response schemas, while the cassette preserves the network log. section 7.4.1
Schemathesis is written in Python and builds on Hypothesis, but targets APIs described by OpenAPI documents and can also test GraphQL APIs. It is especially useful for external or public APIs where consumer-driven contract tests cannot be applied; generated schema tests reduce maintenance when the API changes. section 7.4.1 section 7.8

