🚀 AutoAPI Validator
Automatic OpenAPI request & response validator
A Python package that automatically validates API requests & responses using an OpenAPI (Swagger) file.
✨ Features
✔ Load OpenAPI JSON/YAML specifications
✔ Validate API responses against schemas
✔ Clear, detailed error messages
✔ CLI command for quick validation
✔ Framework-independent
📦 Installation
pip install autoapi-validator
Development Installation
git clone https://github.com/santhosh/autoapi-validator.git
cd autoapi-validator
pip install -e .
🔧 Usage
As a Library
from autoapi_validator import load_openapi, validate_response
# Load OpenAPI specification
spec = load_openapi("openapi.yaml")
# Get schema for a specific component
schema = spec["components"]["schemas"]["User"]
# Validate API response
response = {
"id": 1,
"name": "Santhosh"
}
is_valid, message = validate_response(response, schema)
print(is_valid, message)
FastAPI Integration 🚀
NEW! Automatic validation middleware for FastAPI applications:
from fastapi import FastAPI
from autoapi_validator.integrations.fastapi import configure_validation
app = FastAPI()
# Enable automatic response validation
configure_validation(app, validate_responses=True)
# That's it! All responses are now validated against your OpenAPI schema
Installation with FastAPI support:
pip install autoapi-validator[fastapi]
Features:
- ✅ Automatic response validation using FastAPI's generated OpenAPI schema
- ✅ No duplicate schema definitions needed
- ✅ Validation warnings logged for debugging
- ✅ Non-blocking (responses still sent even if validation fails)
Full example:
from fastapi import FastAPI
from pydantic import BaseModel
from autoapi_validator.integrations.fastapi import configure_validation
app = FastAPI()
configure_validation(app)
class User(BaseModel):
id: int
name: str
email: str
@app.get("/users/{user_id}", response_model=User)
async def get_user(user_id: int):
return {"id": user_id, "name": "John", "email": "john@example.com"}
See examples/fastapi_example.py for a complete working example.
Flask Integration 🍶
NEW! Validation decorators for Flask applications:
from flask import Flask
from autoapi_validator.integrations.flask import setup_flask_validation
app = Flask(__name__)
# Setup validation with your OpenAPI spec
validator = setup_flask_validation(app, "openapi.yaml")
@app.post("/users")
@validator.validate_request_decorator("/users", "POST")
def create_user():
# Request is automatically validated!
return jsonify(request.json)
@app.get("/users/<int:user_id>")
@validator.validate_response_decorator("/users/{userId}", "GET")
def get_user(user_id):
# Response is automatically validated!
return jsonify({"id": user_id, "name": "John"})
Installation with Flask support:
pip install autoapi-validator[flask]
Features:
- ✅ Request validation decorators
- ✅ Response validation decorators
- ✅ Flexible per-endpoint validation
- ✅ Full OpenAPI schema support
See examples/flask_example.py for a complete working example.
Django Integration 🎯
NEW! Middleware and decorators for Django applications:
# settings.py
MIDDLEWARE = [
...
'autoapi_validator.integrations.django.ValidationMiddleware',
]
OPENAPI_SPEC_PATH = 'path/to/openapi.yaml'
OPENAPI_VALIDATE_REQUESTS = False # Optional
OPENAPI_VALIDATE_RESPONSES = True # Optional
# views.py
from django.http import JsonResponse
from autoapi_validator.integrations.django import validate_api
@validate_api("/users", "POST")
def create_user(request):
# Request automatically validated!
data = json.loads(request.body)
return JsonResponse({"id": 1, **data})
@validate_api("/users/{id}", "GET")
def get_user(request, id):
# Response automatically validated!
return JsonResponse({"id": id, "name": "John"})
Installation with Django support:
pip install autoapi-validator[django]
Features:
- ✅ Middleware for automatic validation
- ✅ View decorators for per-endpoint control
- ✅ Django & Django REST Framework support
- ✅ Full OpenAPI schema support
See examples/django_example/ for complete examples.
CI/CD Integration 🔄
GitHub Actions Example:
- name: Validate OpenAPI Spec
run: |
pip install autoapi-validator
python -m autoapi_validator openapi.yaml --info
Pre-commit Hook:
repos:
- repo: local
hooks:
- id: validate-openapi
name: Validate OpenAPI Specification
entry: python -m autoapi_validator
args: ['openapi.yaml', '--info']
language: system
See examples/ci_cd/ for complete configurations.
CLI Usage
# Display help
python -m autoapi_validator
# Load and validate OpenAPI spec
python -m autoapi_validator openapi.yaml
# Show spec information
python -m autoapi_validator openapi.yaml --info
📋 Example
If your API response should be:
{
"id": 1,
"name": "Santhosh"
}
But the API returns:
{
"id": "one",
"fullname": "Santhosh"
}
➡️ AutoAPI Validator will detect the error automatically and provide detailed feedback!
🛠️ Requirements
- Python >= 3.8
- pyyaml >= 6.0
- jsonschema >= 4.0.0
- requests >= 2.28.0
🗺️ Roadmap
Version 0.1.0
- ✅ Load OpenAPI JSON/YAML
- ✅ Validate API responses
- ✅ Clear error messages
- ✅ Basic CLI
Version 0.2.0
- ✅ FastAPI integration middleware
- ✅ Automatic response validation
- ✅ FastAPI example application
Version 0.3.0
- ✅ FastAPI request validation
- ✅ Flask integration with decorators
- ✅ Flask example application
- ✅ CI/CD tools (GitHub Actions, pre-commit hooks)
Version 0.4.0 (Current)
- ✅ Django integration with middleware
- ✅ Django view decorators
- ✅ Django example application
Future Versions
- Auto test generation from OpenAPI specs
- Request body validation improvements
- Real-time API monitoring
- Validation reporting and metrics
📄 License
MIT License - see LICENSE file for details
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
👤 Author
Santhosh
⭐ Star this repo if you find it useful!
Metadata
Release files for autoapi-validator 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| autoapi_validator-0.1.0.tar.gz | 17.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| autoapi_validator-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 35.0 kB
Release files / autoapi_validator-0.1.0.tar.gz
| Download URL | autoapi_validator-0.1.0.tar.gz |
|---|---|
| Size | 17.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b12764a14edbe527c4e79ee35a405e4632d4753771ca0301253b54c8b14efa0e
|
|
BLAKE2b-256 checksum How to use checksums |
dde22c237ec78dc155edc527e2dc0ad3969fbe1fc78d75f6963fb8694e412176
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Release files / autoapi_validator-0.1.0-py3-none-any.whl
| Download URL | autoapi_validator-0.1.0-py3-none-any.whl |
|---|---|
| Size | 17.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
905a0f97719b656025f0836c3c17e54f4b13a99fad69db16208f176a9b9ae5f6
|
|
BLAKE2b-256 checksum How to use checksums |
b3621ff86782cc657193c4cadd54d19c2fb4dbe3fc86f7ce8a597e11c4096593
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.2
|
Security for autoapi-validator 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.