The Swagger Coverage Tool is designed to measure API test coverage based on Swagger documentation. It provides automated tracking and reporting of test coverage for APIs, helping ensure that your endpoints and services are well-tested.
26
stars
0
commits
HTML
primary language
Jun 9, 2026
updated
The Swagger Coverage Tool is designed to measure API test coverage based on Swagger documentation. It provides automated tracking and reporting of test coverage for APIs, helping ensure that your endpoints and services are well-tested.
You can view an example of a coverage report generated by the tool here.
If you have any questions or need assistance, feel free to ask @Nikita Filonov.



pip install swagger-coverage-tool
httpxHere's an example of how to use the tool with httpx:
import httpx
from swagger_coverage_tool import SwaggerCoverageTracker
# Initialize the tracker with service
tracker = SwaggerCoverageTracker(service="api-service")
# Track coverage for the "get_user" endpoint
@tracker.track_coverage_httpx("/api/v1/users/{user_id}")
def get_user(user_id: str):
return httpx.get(f"http://localhost:8000/api/v1/users/{user_id}")
# Track coverage for the "create_user" endpoint
@tracker.track_coverage_httpx("/api/v1/users")
def create_user():
return httpx.post("http://localhost:8000/api/v1/users")
# Make requests
get_user("123")
create_user()
After executing the HTTP requests, coverage data will be automatically collected and saved to the coverage-results
folder by default.
requestsHere's the same example using the requests library:
import requests
from swagger_coverage_tool import SwaggerCoverageTracker
tracker = SwaggerCoverageTracker(service="api-service")
@tracker.track_coverage_requests("/api/v1/users/{user_id}")
def get_user(user_id: str) -> requests.Response:
return requests.get(f"http://localhost:8000/api/v1/users/{user_id}")
@tracker.track_coverage_requests("/api/v1/users")
def create_user() -> requests.Response:
return requests.post("http://localhost:8000/api/v1/users")
get_user()
create_user()
Once the requests have been executed, coverage data will be collected into the coverage-results folder by default. You
can generate a detailed coverage report by running the following command:
swagger-coverage-tool save-report
This will generate a coverage report based on the collected data. The report will be saved as an HTML file (index.html) that you can view or share.
You can configure the Swagger Coverage Tool using a single file: either a YAML, JSON, or .env file. By default, the
tool looks for configuration in:
swagger_coverage_config.yamlswagger_coverage_config.json.env (for environment variable configuration)By default, these files are loaded from the current working directory. Configuration is automatically loaded via get_settings().
You can override default config locations using environment variables:
SWAGGER_COVERAGE_CONFIG_FILE_YAML — path to YAML configSWAGGER_COVERAGE_CONFIG_FILE_JSON — path to JSON configSWAGGER_COVERAGE_CONFIG_FILE_ENV — path to .env configExample:
SWAGGER_COVERAGE_CONFIG_FILE_YAML=./ci/swagger_coverage_config.yaml swagger-coverage-tool save-report
.envAll settings can be declared using environment variables. Nested fields use dot notation, and all variables must be
prefixed with SWAGGER_COVERAGE_.
Example: .env
# Define the services that should be tracked. In the case of multiple services, they can be added in a comma-separated list.
SWAGGER_COVERAGE_SERVICES='[
{
"key": "my-api-service",
"name": "My API Service",
"tags": ["API", "PRODUCTION"],
"repository": "https://github.com/my-api",
"swagger_url": "https://my-api.com/swagger.json"
}
]'
# The directory where the coverage results will be saved.
SWAGGER_COVERAGE_RESULTS_DIR="./coverage-results"
# The file that stores the history of coverage results.
SWAGGER_COVERAGE_HISTORY_FILE="./coverage-history.json"
# The retention limit for the coverage history. It controls how many historical results to keep.
SWAGGER_COVERAGE_HISTORY_RETENTION_LIMIT=30
# Optional file paths for the HTML and JSON reports.
SWAGGER_COVERAGE_HTML_REPORT_FILE="./index.html"
SWAGGER_COVERAGE_JSON_REPORT_FILE="./coverage-report.json"
Note: Either swagger_url or swagger_file is required for each service.
Example: swagger_coverage_config.yaml
services:
- key: "my-api-service"
name: "My API Service"
tags: [ "API", "PRODUCTION" ]
repository: "https://github.com/my-api"
swagger_url: "https://my-api.com/swagger.json"
# swagger_file: "swagger_file_path.json" # Optional if not using swagger_url
results_dir: "./coverage-results"
history_file: "./coverage-history.json"
history_retention_limit: 30
html_report_file: "./index.html"
json_report_file: "./coverage-report.json"
Example: swagger_coverage_config.json
{
"services": [
{
"key": "my-api-service",
"name": "My API Service",
"tags": [
"API",
"PRODUCTION"
],
"repository": "https://github.com/my-api",
"swagger_url": "https://my-api.com/swagger.json"
}
],
"results_dir": "./coverage-results",
"history_file": "./coverage-history.json",
"history_retention_limit": 30,
"html_report_file": "./index.html",
"json_report_file": "./coverage-report.json"
}
| Key | Description | Required | Default |
|---|---|---|---|
services | List of services to track. Each must define key, name, and a swagger_url or swagger_file. | ✅ | — |
services[].key | Unique internal identifier for the service. | ✅ | — |
services[].name | Human-friendly name for the service (used in reports). | ✅ | — |
services[].swagger_url | URL to Swagger (OpenAPI) schema. | ❗ | — |
services[].swagger_file | Local file path to Swagger schema (alternative to URL). | ❗ | — |
services[].tags | Optional tags used in reports for filtering or grouping. | ❌ | — |
services[].repository | Optional repository URL (will be shown in report). | ❌ | — |
results_dir | Directory to store raw coverage result files. | ❌ | ./coverage-results |
history_file | File to store historical coverage data. | ❌ | ./coverage-history.json |
history_retention_limit | Maximum number of historical entries to keep. | ❌ | 30 |
html_report_file | Path to save the final HTML report (if enabled). | ❌ | ./index.html |
json_report_file | Path to save the raw JSON report (if enabled). | ❌ | ./coverage-report.json |
Once configured, the tool automatically:
coverage-results/.No manual data manipulation is required – the tool handles everything automatically based on your config.
The Swagger Coverage Tool provides several CLI commands to help with managing and generating coverage reports.
save-reportGenerates a detailed coverage report based on the collected result files. This command will process all the raw coverage
data stored in the coverage-results directory and generate an HTML report.
Usage:
swagger-coverage-tool save-report
copy-reportThis is an internal command mainly used during local development. It updates the report template for the generated coverage reports. It is typically used to ensure that the latest report template is available when you generate new reports.
Usage:
swagger-coverage-tool copy-report
print-configPrints the resolved configuration to the console. This can be useful for debugging or verifying that the configuration file has been loaded and parsed correctly.
Usage:
swagger-coverage-tool print-config
swagger_coverage_config.yaml, swagger_coverage_config.json, or .env,
or a custom path set via SWAGGER_COVERAGE_CONFIG_FILE_*) and prints the final configuration values to the console.HTML
87.9%
Python
12.1%
The Swagger Coverage Tool is designed to measure API test coverage based on Swagger documentation. It provides automated tracking and reporting of test coverage for APIs, helping ensure that your endpoints and services are well-tested.
26
stars
0
commits
HTML
primary language
Jun 9, 2026
updated
The Swagger Coverage Tool is designed to measure API test coverage based on Swagger documentation. It provides automated tracking and reporting of test coverage for APIs, helping ensure that your endpoints and services are well-tested.
You can view an example of a coverage report generated by the tool here.
If you have any questions or need assistance, feel free to ask @Nikita Filonov.



pip install swagger-coverage-tool
httpxHere's an example of how to use the tool with httpx:
import httpx
from swagger_coverage_tool import SwaggerCoverageTracker
# Initialize the tracker with service
tracker = SwaggerCoverageTracker(service="api-service")
# Track coverage for the "get_user" endpoint
@tracker.track_coverage_httpx("/api/v1/users/{user_id}")
def get_user(user_id: str):
return httpx.get(f"http://localhost:8000/api/v1/users/{user_id}")
# Track coverage for the "create_user" endpoint
@tracker.track_coverage_httpx("/api/v1/users")
def create_user():
return httpx.post("http://localhost:8000/api/v1/users")
# Make requests
get_user("123")
create_user()
After executing the HTTP requests, coverage data will be automatically collected and saved to the coverage-results
folder by default.
requestsHere's the same example using the requests library:
import requests
from swagger_coverage_tool import SwaggerCoverageTracker
tracker = SwaggerCoverageTracker(service="api-service")
@tracker.track_coverage_requests("/api/v1/users/{user_id}")
def get_user(user_id: str) -> requests.Response:
return requests.get(f"http://localhost:8000/api/v1/users/{user_id}")
@tracker.track_coverage_requests("/api/v1/users")
def create_user() -> requests.Response:
return requests.post("http://localhost:8000/api/v1/users")
get_user()
create_user()
Once the requests have been executed, coverage data will be collected into the coverage-results folder by default. You
can generate a detailed coverage report by running the following command:
swagger-coverage-tool save-report
This will generate a coverage report based on the collected data. The report will be saved as an HTML file (index.html) that you can view or share.
You can configure the Swagger Coverage Tool using a single file: either a YAML, JSON, or .env file. By default, the
tool looks for configuration in:
swagger_coverage_config.yamlswagger_coverage_config.json.env (for environment variable configuration)By default, these files are loaded from the current working directory. Configuration is automatically loaded via get_settings().
You can override default config locations using environment variables:
SWAGGER_COVERAGE_CONFIG_FILE_YAML — path to YAML configSWAGGER_COVERAGE_CONFIG_FILE_JSON — path to JSON configSWAGGER_COVERAGE_CONFIG_FILE_ENV — path to .env configExample:
SWAGGER_COVERAGE_CONFIG_FILE_YAML=./ci/swagger_coverage_config.yaml swagger-coverage-tool save-report
.envAll settings can be declared using environment variables. Nested fields use dot notation, and all variables must be
prefixed with SWAGGER_COVERAGE_.
Example: .env
# Define the services that should be tracked. In the case of multiple services, they can be added in a comma-separated list.
SWAGGER_COVERAGE_SERVICES='[
{
"key": "my-api-service",
"name": "My API Service",
"tags": ["API", "PRODUCTION"],
"repository": "https://github.com/my-api",
"swagger_url": "https://my-api.com/swagger.json"
}
]'
# The directory where the coverage results will be saved.
SWAGGER_COVERAGE_RESULTS_DIR="./coverage-results"
# The file that stores the history of coverage results.
SWAGGER_COVERAGE_HISTORY_FILE="./coverage-history.json"
# The retention limit for the coverage history. It controls how many historical results to keep.
SWAGGER_COVERAGE_HISTORY_RETENTION_LIMIT=30
# Optional file paths for the HTML and JSON reports.
SWAGGER_COVERAGE_HTML_REPORT_FILE="./index.html"
SWAGGER_COVERAGE_JSON_REPORT_FILE="./coverage-report.json"
Note: Either swagger_url or swagger_file is required for each service.
Example: swagger_coverage_config.yaml
services:
- key: "my-api-service"
name: "My API Service"
tags: [ "API", "PRODUCTION" ]
repository: "https://github.com/my-api"
swagger_url: "https://my-api.com/swagger.json"
# swagger_file: "swagger_file_path.json" # Optional if not using swagger_url
results_dir: "./coverage-results"
history_file: "./coverage-history.json"
history_retention_limit: 30
html_report_file: "./index.html"
json_report_file: "./coverage-report.json"
Example: swagger_coverage_config.json
{
"services": [
{
"key": "my-api-service",
"name": "My API Service",
"tags": [
"API",
"PRODUCTION"
],
"repository": "https://github.com/my-api",
"swagger_url": "https://my-api.com/swagger.json"
}
],
"results_dir": "./coverage-results",
"history_file": "./coverage-history.json",
"history_retention_limit": 30,
"html_report_file": "./index.html",
"json_report_file": "./coverage-report.json"
}
| Key | Description | Required | Default |
|---|---|---|---|
services | List of services to track. Each must define key, name, and a swagger_url or swagger_file. | ✅ | — |
services[].key | Unique internal identifier for the service. | ✅ | — |
services[].name | Human-friendly name for the service (used in reports). | ✅ | — |
services[].swagger_url | URL to Swagger (OpenAPI) schema. | ❗ | — |
services[].swagger_file | Local file path to Swagger schema (alternative to URL). | ❗ | — |
services[].tags | Optional tags used in reports for filtering or grouping. | ❌ | — |
services[].repository | Optional repository URL (will be shown in report). | ❌ | — |
results_dir | Directory to store raw coverage result files. | ❌ | ./coverage-results |
history_file | File to store historical coverage data. | ❌ | ./coverage-history.json |
history_retention_limit | Maximum number of historical entries to keep. | ❌ | 30 |
html_report_file | Path to save the final HTML report (if enabled). | ❌ | ./index.html |
json_report_file | Path to save the raw JSON report (if enabled). | ❌ | ./coverage-report.json |
Once configured, the tool automatically:
coverage-results/.No manual data manipulation is required – the tool handles everything automatically based on your config.
The Swagger Coverage Tool provides several CLI commands to help with managing and generating coverage reports.
save-reportGenerates a detailed coverage report based on the collected result files. This command will process all the raw coverage
data stored in the coverage-results directory and generate an HTML report.
Usage:
swagger-coverage-tool save-report
copy-reportThis is an internal command mainly used during local development. It updates the report template for the generated coverage reports. It is typically used to ensure that the latest report template is available when you generate new reports.
Usage:
swagger-coverage-tool copy-report
print-configPrints the resolved configuration to the console. This can be useful for debugging or verifying that the configuration file has been loaded and parsed correctly.
Usage:
swagger-coverage-tool print-config
swagger_coverage_config.yaml, swagger_coverage_config.json, or .env,
or a custom path set via SWAGGER_COVERAGE_CONFIG_FILE_*) and prints the final configuration values to the console.HTML
87.9%
Python
12.1%