Flow icon
Commands icon
Script icon
Log icon
If icon
Fail icon

Schemathesis API Contract Gate

Run Schemathesis property-based tests against your OpenAPI schema after each staging deploy and block releases on server errors or contract breaks.

Categories
Infrastructure

An OpenAPI schema is a promise: these operations, these status codes, these response shapes. Hand-written tests cover the happy paths you thought of; the 500 on a long string or the undocumented 422 ships anyway. This blueprint runs Schemathesis, which generates property-based test cases straight from the schema, against a running staging API, keeps its JUnit and JSON reports on the execution, and turns its findings into a pass/fail gate that release flows can wait on.

How it works

  1. after_staging_deploy (io.kestra.plugin.core.trigger.Flow) starts the gate when the deploy_staging flow ends in SUCCESS. It ships disabled: true; you can also run the flow by hand.
  2. fuzz_api (io.kestra.plugin.scripts.python.Commands) installs a pinned schemathesis==4.32.0 in a python:3.12-slim container and runs st run with --checks all (server errors, status-code, content-type, header and response-schema conformance, negative data rejection and more), at most max_examples cases per operation. Schemathesis exits non-zero when it finds failures, and script tasks stop on the first failing command, so the exit code is captured (|| rc=$?) and written to a file instead of failing the task; junit.xml and run.json are always kept as output files.
  3. evaluate_report (io.kestra.plugin.scripts.python.Script) reads run.json, counts failures by Schemathesis severity (critical, high, medium, low), lists each failure type with the operations it hit, and counts the ones in the fail_on severities as blocking. No report at all (schema unreachable, crash) counts as blocking.
  4. log_findings (io.kestra.plugin.core.log.Log) logs the verdict, the counts and one line per failure type, for example ST101 Server error [critical] x1: POST /api/read.
  5. gate (io.kestra.plugin.core.flow.If) fails the execution through io.kestra.plugin.core.execution.Fail when anything is blocking, otherwise logs a pass. The verdict and junit_report flow outputs expose the result.

What you get

  • Hundreds of schema-derived requests per run against every operation, not just the cases someone wrote tests for.
  • A BLOCKED / PASSED_WITH_FINDINGS / PASSED / NO_REPORT verdict, and a failed execution when the release should stop.
  • The JUnit XML and the JSON run report attached to each execution, with Schemathesis' own curl reproduction for every failure.
  • A severity threshold you choose: block on server errors only, or on any contract drift.

Who it's for

  • Backend and API teams that publish an OpenAPI schema (FastAPI, Spring, NestJS, Django REST and others generate one).
  • Platform and QA teams who own the release gates between staging and production.

Why orchestrate this with Kestra

The same st run in a laptop terminal is forgotten after the first week. In Kestra it runs on every staging deploy through a Flow trigger, the reports are versioned with the execution, the verdict is a typed output, and a failed gate stops the downstream release with a clear error and full logs instead of a red line in someone's terminal.

Prerequisites

  • A running API you are allowed to fuzz (staging or a preview environment, never production), and its OpenAPI schema URL.
  • A Kestra worker that can run containers (Docker or Kubernetes task runner) and reach the API and PyPI.
  • Optional: a deploy_staging flow in company.team for the trigger, or change the trigger to your own deploy flow.

Secrets

  • None are required for a public staging API. For an authenticated one, add a secret such as API_TOKEN and set extra_header to an Authorization: Bearer header whose value is the Pebble expression secret('API_TOKEN'), so the token stays masked in logs.

Quick start

  1. Set schema_url and base_url to your staging API (and extra_header if it needs one).
  2. Execute the flow with the defaults and read log_findings; open junit.xml from the fuzz_api outputs to see each failure with its curl reproduction.
  3. Choose fail_on (keep critical,high to start, tighten later).
  4. Point after_staging_deploy at your deploy flow and enable it.

How to extend

  • Add --include-path-regex or --exclude-method to st run to scope the gate to the operations a release touched.
  • Commit a Schemathesis --baseline file for known findings so only new failures block.
  • Post log_findings to Slack or open a ticket per new failure type with the issue tracker plugins.
  • Run one execution per service with a Loop over a list of schema URLs.

Links

Share this Blueprint
See How

New to Kestra?

Use blueprints to kickstart your first workflows.