Skip to main content

SwaggerForge

Automatic pytest test generation from OpenAPI (Swagger) specifications.

SwaggerForge is a Python library and command-line tool that reads an OpenAPI specification and generates ready-to-run pytest test files - one per resource covering positive, negative, boundary, and boolean scenarios grounded in established test-design techniques.

Features

  • Reads OpenAPI 3.x specifications in JSON or YAML
  • Resolves $ref references automatically
  • Generates one pytest file per resource tag
  • Produces six scenario types per endpoint where applicable:
    • Positive >>> valid request, expects a 2xx response and validates the response schema
    • Missing required field >>> omits a required field, expects 400
    • Wrong data type >>> sends a mistyped field, expects 400/422
    • Nonexistent resource >>> requests an unlikely identifier, expects 404
    • Boundary values >>> tests values at and just beyond declared numeric/length limits (Boundary Value Analysis)
    • Boolean coverage >>> exercises both true and false for boolean fields
  • Deterministic output: the same specification always produces identical tests
  • Generated files use session-scoped pytest fixtures and run with no manual edits
  • Optional swaggerforge.toml config file for project-level defaults

Requirements

  • Python 3.10 or newer

Installation

pip install swaggerforge

Usage

Generate tests from a specification, pointing at the base URL of the API under test:

swaggerforge generate --spec swagger.json --url http://localhost:8080

This reads swagger.json, writes one test_<resource>.py file per resource tag into the output directory (default: tests_generated/), and the files can be run immediately:

pytest tests_generated

Options

Option Description Default
--spec Path to the OpenAPI specification (JSON or YAML) (required)
--url Base URL of the API under test (required unless in config)
--output Directory for the generated test files tests_generated
--config Path to a configuration file ./swaggerforge.toml if present

Configuration

Options that stay the same across runs can be kept in a swaggerforge.toml file instead of being passed on the command line. The file is picked up automatically from the directory where the tool is run, or an explicit path can be given with --config.

# swaggerforge.toml
base_url = "http://localhost:8080"
output_dir = "tests_generated"
timeout = 30
Key Type Effect
base_url string Base URL of the API; makes --url optional
output_dir string Directory for generated files
timeout integer Embeds timeout=<n> into every generated HTTP request call

Values given on the command line always take precedence over the config file. Without a timeout, generated tests place no time limit on requests - setting one makes test runs fail fast when the API is unreachable.

How it works

SwaggerForge runs a six-stage pipeline: the specification is validated, parsed into an internal model (with $refs resolved), turned into test scenarios based on test-design techniques, rendered into pytest code via templates, and written to per-resource files.

Limitations

  • Targets OpenAPI 3.x with JSON request bodies
  • Authentication is not yet handled (planned)
  • Boundary tests require the specification to declare numeric/length constraints

License

This project is licensed under the MIT License - see the LICENSE file.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swaggerforge-0.2.0.tar.gz (20.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

swaggerforge-0.2.0-py3-none-any.whl (16.5 kB view details)

Uploaded Python 3

File details

Details for the file swaggerforge-0.2.0.tar.gz.

File metadata

  • Download URL: swaggerforge-0.2.0.tar.gz
  • Upload date:
  • Size: 20.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for swaggerforge-0.2.0.tar.gz
Algorithm Hash digest
SHA256 6b95e087bbe57a446e027ebfbefe37806f8efc51e5b3f0b62c30fe35c0e3cfa5
MD5 d802e751a419f671199e2b5955b21c47
BLAKE2b-256 f7ca42b9366e61640e479cb568f75518c115ae03a9ac3344962f1d17f987d781

See more details on using hashes here.

File details

Details for the file swaggerforge-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: swaggerforge-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for swaggerforge-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83047d1cc7502b20b3eb7bd3d3c5926cfbd210a7871e38c0aa342fadd74d0b8c
MD5 4fbc68a66d49152492ca91917eddac24
BLAKE2b-256 95f15893bce41de1c8d1387e2ba85d2658404864cd37114519ddfd1a2c9f1051

See more details on using hashes here.

Release history Release notifications | RSS feed

0.3.0

2 files

This release

0.2.0 This release

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page