Skip to main content

Validate JSON payloads against AsyncAPI specifications with detailed error reporting

Project description

AsyncAPI Payload Validator

PyPI version Python Support License

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


Download files

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

Source Distribution

asyncapi_payload_validator-1.0.1.tar.gz (37.7 kB view details)

Uploaded Source

Built Distribution

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

asyncapi_payload_validator-1.0.1-py3-none-any.whl (32.2 kB view details)

Uploaded Python 3

File details

Details for the file asyncapi_payload_validator-1.0.1.tar.gz.

File metadata

File hashes

Hashes for asyncapi_payload_validator-1.0.1.tar.gz
Algorithm Hash digest
SHA256 f2f7287a88d0d0bfadead396b817681d4ca74ae8aac4e0c139845e4f43d9b115
MD5 dc9e4492c35436e23da6019c0d656cc5
BLAKE2b-256 94c8d65d5170748e864847ef5b1bd9bf23c29679aa79d0380ffd052671aadf86

See more details on using hashes here.

Provenance

The following attestation bundles were made for asyncapi_payload_validator-1.0.1.tar.gz:

Publisher: pypi-publish.yml on ingka-group/asyncapi-payload-validator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file asyncapi_payload_validator-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for asyncapi_payload_validator-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 05edc841687fddecc51a6b9f5c31987dd7a22b808a4c20fd807f9e157bc9b8fd
MD5 6a42eb9dbcd3b5bd28b29bbb83ab01a6
BLAKE2b-256 1b4087053fe54848a991b200e2ad09ceb52839658e73d0b72454cea9132fa36d

See more details on using hashes here.

Provenance

The following attestation bundles were made for asyncapi_payload_validator-1.0.1-py3-none-any.whl:

Publisher: pypi-publish.yml on ingka-group/asyncapi-payload-validator

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page