This repository has been archived by the owner on Mar 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #209 from quantmind/ls-docs
required is True by default
- Loading branch information
Showing
8 changed files
with
193 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -238,6 +238,7 @@ Contents | |
:maxdepth: 2 | ||
|
||
reference | ||
validation | ||
queries | ||
env | ||
glossary | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
.. _aio-openapi-validation: | ||
|
||
|
||
=========== | ||
Validation | ||
=========== | ||
|
||
Validation is an important component of the library and it is designed to validate | ||
data to and from JSON serializable objects. | ||
|
||
To validate a simple list of integers | ||
|
||
.. code-block:: python | ||
from typing import List | ||
from openapi.data.validate import validate | ||
validate(List[int], [5,2,4,8]) | ||
# ValidatedData(data=[5, 2, 4, 8], errors={}) | ||
validate(List[int], [5,2,"5",8]) | ||
# ValidatedData(data=None, errors='not valid type') | ||
The main object for validation are python dataclasses: | ||
|
||
|
||
.. code-block:: python | ||
from dataclasses import dataclass | ||
from typing import Union | ||
@dataclass | ||
class Foo: | ||
text: str | ||
param: Union[str, int] | ||
done: bool = False | ||
validate(Foo, {}) | ||
# ValidatedData(data=None, errors={'text': 'required', 'param': 'required'}) | ||
validate(Foo, dict(text=1)) | ||
# ValidatedData(data=None, errors={'text': 'not valid type', 'param': 'required'}) | ||
validate(Foo, dict(text="ciao", param=3)) | ||
# ValidatedData(data={'text': 'ciao', 'param': 3, 'done': False}, errors={}) | ||
Validated Schema | ||
================ | ||
|
||
Use the :func:`.validated_schema` to validate input data and return an instance of the | ||
validation schema. This differes from :func:`.validate` only when dataclasses are involved | ||
|
||
.. code-block:: python | ||
from openapi.data.validate import validated_schema | ||
validated_schema(Foo, dict(text="ciao", param=3)) | ||
# Foo(text='ciao', param=3, done=False) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters