Validate JSON payloads against AsyncAPI specifications with detailed error reporting
Project description
AsyncAPI Payload Validator
A Python tool for validating JSON message payloads against AsyncAPI specifications. Performs detailed JSON Schema validation including type checking, constraints, patterns, enums, and composition rules.
Features
- Comprehensive validation - types, required fields, string length, patterns, enums, numeric constraints, oneOf/anyOf/allOf
- Lenient type coercion - string numbers and booleans accepted where appropriate
- AsyncAPI 2.x and 3.x - supports both specification versions
- HTML reports - detailed reports with line-by-line source highlighting
- Jinja2 templates - validate template structure before rendering
- CI/CD ready - exit codes, GitHub Actions and GitLab CI examples
Installation
pip install asyncapi-payload-validator
Install from source
git clone https://github.com/ingka-group/asyncapi-payload-validator.git
cd asyncapi-payload-validator
pip install .
For development: pip install -e ".[dev]"
Quick Start
Command Line
# Basic validation
asyncapi-validate payload.json asyncapi-spec.yaml
# Generate HTML report
asyncapi-validate payload.json asyncapi-spec.yaml --html-report report.html
# Validate specific message by ID
asyncapi-validate payload.json asyncapi-spec.yaml --message-id UserSignedUp
# Validate Jinja2 template structure
asyncapi-validate template.json spec.yaml --render-jinja2
# Validate rendered template with context
asyncapi-validate template.json spec.yaml --render-jinja2 --jinja2-context context.json
Python Library
import json, yaml
from pathlib import Path
from asyncapi_payload_validator import validate_payload
payload = json.loads(Path('payload.json').read_text())
spec = yaml.safe_load(Path('asyncapi.yaml').read_text())
result = validate_payload(payload, spec)
if result['valid']:
print("Validation passed!")
else:
print(f"{result['summary']['total_violations']} violation(s)")
for category, violations in result['violations'].items():
for v in violations:
print(f" - {v}")
See Python API Reference for the full API, return value structure, and advanced usage.
Validation Rules
| Icon | Category | Description |
|---|---|---|
| ➕ | Extra Attributes | Fields in payload not declared in schema |
| ❌ | Type Mismatches | Incorrect data types (with lenient coercion) |
| 🚫 | Missing Required | Required fields absent from payload |
| ↔️ | Length Violations | String minLength/maxLength constraints |
| #️⃣ | Pattern Violations | Regex pattern mismatches |
| ✅ | Enum Violations | Values not in allowed enum list |
| 🔢 | Numeric Violations | min/max/multipleOf constraints |
| 🧩 | Composition Violations | oneOf/anyOf/allOf rule failures |
Exit Codes
| Code | Meaning |
|---|---|
0 |
Validation passed |
1 |
Validation failed (violations found) |
2 |
Error (invalid arguments, file not found) |
130 |
Cancelled by user (Ctrl+C) |
Documentation
| Guide | Description |
|---|---|
| Examples and Output | Output format, real-world examples, icon reference |
| Python API | Programmatic usage, return structure, individual functions |
| CI/CD Integration | GitHub Actions, GitLab CI examples |
| Advanced Features | Jinja2 templates, type coercion, composition, troubleshooting |
Contributing
Contributions are welcome! See CONTRIBUTING.md for guidelines.
License
MIT - see LICENCE.md for details.
Links
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file asyncapi_payload_validator-1.0.0.tar.gz.
File metadata
- Download URL: asyncapi_payload_validator-1.0.0.tar.gz
- Upload date:
- Size: 37.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75d31c7ddbe251cd91d4a4eea05b5cb284e145099afd25390ed6abcee55c3082
|
|
| MD5 |
cb8aeee25de2d901c5d9a46fd69b8f29
|
|
| BLAKE2b-256 |
dc3379ba9c8431a226bb646280bed874ad0da7864613222984e8b3baa67a5b82
|
Provenance
The following attestation bundles were made for asyncapi_payload_validator-1.0.0.tar.gz:
Publisher:
pypi-publish.yml on ingka-group/asyncapi-payload-validator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
asyncapi_payload_validator-1.0.0.tar.gz -
Subject digest:
75d31c7ddbe251cd91d4a4eea05b5cb284e145099afd25390ed6abcee55c3082 - Sigstore transparency entry: 995724865
- Sigstore integration time:
-
Permalink:
ingka-group/asyncapi-payload-validator@db590b57d514d52e28b6481344b06e27da1f5b9c -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ingka-group
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@db590b57d514d52e28b6481344b06e27da1f5b9c -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file asyncapi_payload_validator-1.0.0-py3-none-any.whl.
File metadata
- Download URL: asyncapi_payload_validator-1.0.0-py3-none-any.whl
- Upload date:
- Size: 32.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d92f4f08aa6c0a1bcab2a2e1390cbf72a84e4fed3e872c036144743f6129d57
|
|
| MD5 |
8f2bfa5df431220c3e43f316fbd9c020
|
|
| BLAKE2b-256 |
81a91b36e9e73161017ea5095f4bcdb7e192cc4aa5ae526ab6e44c51dd16a753
|
Provenance
The following attestation bundles were made for asyncapi_payload_validator-1.0.0-py3-none-any.whl:
Publisher:
pypi-publish.yml on ingka-group/asyncapi-payload-validator
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
asyncapi_payload_validator-1.0.0-py3-none-any.whl -
Subject digest:
6d92f4f08aa6c0a1bcab2a2e1390cbf72a84e4fed3e872c036144743f6129d57 - Sigstore transparency entry: 995724913
- Sigstore integration time:
-
Permalink:
ingka-group/asyncapi-payload-validator@db590b57d514d52e28b6481344b06e27da1f5b9c -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ingka-group
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@db590b57d514d52e28b6481344b06e27da1f5b9c -
Trigger Event:
workflow_dispatch
-
Statement type: