From aws-test-plugin
Generate contract tests that validate API schemas, request/response shapes, required fields, security definitions, and step function input/output contracts. Works with OpenAPI/Swagger specs, SAM templates, and CloudFormation. Uses jsonschema and pydantic for validation. All tests run offline with zero network calls. Use when asked to write contract tests, schema tests, API contract validation, validate OpenAPI spec, or verify request/response shapes for any AWS Python project.
How this skill is triggered — by the user, by Claude, or both
Slash command
/aws-test-plugin:aws-contract-testingThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
Generate offline contract tests by reading OpenAPI specs, SAM templates, and
Generate offline contract tests by reading OpenAPI specs, SAM templates, and CloudFormation definitions. No network calls needed.
Search the project for:
swagger.yml, swagger.yaml, openapi.yml, openapi.yaml, openapi.jsontemplate.yaml with AWS::Serverless::Api + inline swaggerAWS::ApiGateway::RestApi + Body propertyapi.json or any file containing "openapi" or "swagger" keysFrom the spec, extract:
components.schemas (or definitions in Swagger 2)See references/openapi-patterns.md for full patterns.
"""Verify all expected schemas exist in the spec."""
import yaml
import pytest
from pathlib import Path
SPEC_PATH = Path("path/to/swagger.yml") # Discovered in Phase 1
@pytest.fixture(scope="module")
def spec():
return yaml.safe_load(SPEC_PATH.read_text(encoding="utf-8"))
@pytest.fixture(scope="module")
def schemas(spec):
return spec.get("components", spec.get("definitions", {})).get("schemas", {})
class TestSchemaCompleteness:
# Auto-populated from spec analysis:
EXPECTED_SCHEMAS = [
# List every schema name found in the spec
]
@pytest.mark.parametrize("schema_name", EXPECTED_SCHEMAS)
def test_schema_exists(self, schemas, schema_name):
assert schema_name in schemas, f"Missing schema: {schema_name}"
For each endpoint with a request body:
from jsonschema import validate, ValidationError
class TestCreateResourceContract:
def test_valid_request_passes(self, schemas):
schema = schemas["createResourceRequest"]
payload = {
# All required fields with valid values
}
validate(instance=payload, schema=schema) # No error = pass
def test_missing_required_field_fails(self, schemas):
schema = schemas["createResourceRequest"]
with pytest.raises(ValidationError):
validate(instance={}, schema=schema)
def test_extra_field_accepted_or_rejected(self, schemas):
schema = schemas["createResourceRequest"]
payload = {
# Required fields + an extra unknown field
"unknownField": "value",
}
if schema.get("additionalProperties") is False:
with pytest.raises(ValidationError):
validate(instance=payload, schema=payload)
else:
validate(instance=payload, schema=schema) # Should pass
class TestSecurityContracts:
def test_security_scheme_defined(self, spec):
security_schemes = (
spec.get("components", {}).get("securitySchemes", {})
or spec.get("securityDefinitions", {})
)
assert len(security_schemes) > 0, "No security schemes defined"
def test_all_endpoints_have_security(self, spec):
global_security = spec.get("security", [])
paths = spec.get("paths", {})
for path, methods in paths.items():
for method, details in methods.items():
if method in ("get", "post", "put", "delete", "patch"):
endpoint_security = details.get("security", global_security)
assert endpoint_security, (
f"{method.upper()} {path} has no security"
)
If a step function definition is found, generate input/output contract tests:
from pydantic import BaseModel
from typing import Optional
class StepFunctionInput(BaseModel):
"""Model derived from the first state's expected input."""
# Populate fields from state machine definition
pass
class StepFunctionOutput(BaseModel):
"""Model derived from the last state's output."""
pass
def test_valid_input():
data = {/* valid fields */}
model = StepFunctionInput(**data)
assert model # Pydantic validates on construction
def test_missing_required_field():
with pytest.raises(Exception):
StepFunctionInput() # Missing required fields
pytest tests/contract/ -v -m contract --tb=short
npx claudepluginhub whitewhiteqq/aws-test-plugin --plugin claude-aws-test-pluginChecks and configures API contract testing with Pact for consumer-provider agreements, OpenAPI validation, and schema testing. Supports JS/Python projects with --check-only, --fix options.
Checks and configures API contract testing with Pact for consumer-provider agreements, OpenAPI spec validation, and schema testing. Use for CI breaking change detection and compliance checks.
Validates OpenAPI/Swagger contracts through a multi-tool pipeline: Spectral linting, oasdiff breaking change detection, Prism mocking, and Schemathesis fuzzing. Use when verifying API spec compliance.