Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Validation Schema Examples #386

Closed
PixelAmp opened this issue Apr 6, 2021 · 3 comments
Closed

Add Validation Schema Examples #386

PixelAmp opened this issue Apr 6, 2021 · 3 comments
Assignees
Labels
documentation Improvements or additions to documentation
Milestone

Comments

@PixelAmp
Copy link

PixelAmp commented Apr 6, 2021

What were you initially searching for in the docs?
I wanted to implement the Validation utility to validate data received by my requests, but was unfamiliar with writing JSONSchema.

Is this related to an existing part of the documentation? Please share a link
https://awslabs.github.io/aws-lambda-powertools-python/latest/utilities/validation/

There are no working examples of valid json_schema_dict within the documentation.
They are all collapsed making it difficult to get an idea for how JSONSchema should be structured.

json_schema_dict = {..}

Describe how we could make it clearer
The fastjsonschema library is linked, however an actual example within this documentation page would make improve comprehension.

For example Unwrapping events prior to validation has sample_wrapped_event.json, but it does not show what the accompanying schema should look like.

If you have a proposed update, please share it here
I suggest adding a tab with some example inputs and their schema. as well as adding what a SchemaValidationError exception looks like for different scenarios.

For example, the a rudimentary validation schema for sample_wrapped_event.json would likely look like this (but with better regex and pattern matching)

json_schema_dict = {
    "type": "object",
    "properties": {
        "id": {"type": "string"},
        "detail-type": {"type": "string"},
        "source": {"type": "string"},
        "account": {"type": "string"},
        "time": {"type": "string"},
        "region": {"type": "string"},
        "resources": {"type": "string"},
        "detail": {
            "type": "object",
            "properties": {
                "message": {"type": "string"},
                "username": {"type": "string"},
            }
        }
    }
}

@PixelAmp PixelAmp added the documentation Improvements or additions to documentation label Apr 6, 2021
@heitorlessa heitorlessa self-assigned this Apr 6, 2021
@heitorlessa
Copy link
Contributor

Hola @PixelAmp - Thanks for helping us improve the documentation! We'll surely do that after this week's release :)

In the meantime, you can find a few within validator's functional tests: https://github.com/awslabs/aws-lambda-powertools-python/blob/develop/tests/functional/validator/conftest.py

Background: Historically, it wasn't there because the older documentation system didn't support tabbed content and made it more verbose, so we stripped it.

@heitorlessa
Copy link
Contributor

hey @PixelAmp - This is now live in staging: https://awslabs.github.io/aws-lambda-powertools-python/develop/utilities/validation/

I've added a JSON Schema and event for every sample, reformat navigation to use the new Getting started vs Advanced use cases too.

Let me know if that helps :)

@PixelAmp
Copy link
Author

PixelAmp commented Apr 8, 2021

That looks great!

Those examples significantly improve the readability of the module and will make it a lot easier to quickly get it up and running.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
Development

No branches or pull requests

2 participants