Skip to main content

No project description provided

Project description

powertools-oas-validator


PyPI version Release CI

Introduction

Powertools for AWS Lambda (Python) is an awesome set of tools for supercharging your lambdas. Powertools supports validating incoming requests (or event in PT lingo) against JSONSchema which is not ideal if you are using OpenAPI schemas to define your API contracts.

The Powertools OAS Validator adds a decorator that you can use with your lambda handlers and have the events validated against an OpenAPI schema instead.

Installation

Poetry: poetry add powertools-oas-validator

Pip: pip install powertools-oas-validator

Usage

Decorate your functions with @validate_request(oas_path="openapi.yaml") and your request/event (and schema) will be validated on a request.

Minimal Example

from typing import Dict
from aws_lambda_powertools.event_handler import APIGatewayRestResolver, Response
from aws_lambda_powertools.utilities.typing import LambdaContext
from powertools_oas_validator.middleware import validate_request


app = APIGatewayRestResolver()

@app.post("/example")
def example() -> Response:
  ...

@validate_request(oas_path="openapi.yaml")
def lambda_handler(event: Dict, context: LambdaContext) -> Dict:
    response = app.resolve(event, context)

    return response

Error Handling

If the validation fails, the decorator throws a SchemaValidatonError with relevant information about the failed validation.

Know Issues

While all validation errors are caught, there is only limited information about the various errors. The decorator will try its best to throw a SchemaValidatonError (same as the Powertools validator would), with as much of the optional attributes as possible.

In summary, it is possible that not all SchemaValidationErrors's will have a nice validation message, in case you rely on piping it straight back to the client.

Contributions

Please make a pull request and I will review it ASAP.

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

powertools_oas_validator-0.5.2.tar.gz (7.9 kB view details)

Uploaded Source

File details

Details for the file powertools_oas_validator-0.5.2.tar.gz.

File metadata

  • Download URL: powertools_oas_validator-0.5.2.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.8.17 Linux/5.15.0-1040-azure

File hashes

Hashes for powertools_oas_validator-0.5.2.tar.gz
Algorithm Hash digest
SHA256 3e8980231000bf0570684d48cd8ae3ab4024f0cfcc272f3f17af6864099f67da
MD5 6a8d6cd238daa9cec343884a92f43c1c
BLAKE2b-256 5f050e54fd2dc8f074907591af262f89378aaceaea56331e274079e84f63c08a

See more details on using hashes here.

Supported by

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