Metadata-Version: 2.4
Name: swaggerforge
Version: 0.1.0
Summary: Automatic pytest test generation from OpenAPI (Swagger) specifications
Author: Viktor Pylypenko
License-Expression: MIT
Keywords: openapi,swagger,pytest,test generation,api testing
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: click>=8.0
Requires-Dist: prance>=23.6.21.0
Requires-Dist: openapi-core>=0.18
Requires-Dist: openapi-spec-validator>=0.7
Requires-Dist: jinja2>=3.0
Requires-Dist: requests>=2.28
Requires-Dist: jsonschema>=4.0
Provides-Extra: dev
Requires-Dist: pytest>=9.0; extra == "dev"
Requires-Dist: flake8>=7.0; extra == "dev"
Dynamic: license-file

# 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

## Requirements

- Python 3.10 or newer

## Installation

```bash
pip install swaggerforge
```

## Usage

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

```bash
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:

```bash
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)*       |
| `--output` | Directory for the generated test files             | `tests_generated`  |

## How it works

SwaggerForge runs a six-stage pipeline: the specification is validated, parsed
into an internal model (with `$ref`s 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](LICENSE) file.
