You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -66,98 +65,50 @@ Firstly create your specification object.
66
65
67
66
spec = Spec.from_file_path('openapi.json')
68
67
69
-
Now you can use it to validate against requests and/or responses.
70
-
71
-
Request
72
-
*******
73
-
74
-
Use ``validate_request`` function to validate request against a given spec.
68
+
Now you can use it to validate and unmarshal against requests and/or responses.
75
69
76
70
.. code-block:: python
77
71
78
-
from openapi_core import validate_request
79
-
80
-
# raise error if request is invalid
81
-
result = validate_request(request, spec=spec)
72
+
from openapi_core import unmarshal_request
82
73
83
-
Request object should implement OpenAPI Request protocol (See `Integrations <https://openapi-core.readthedocs.io/en/latest/integrations.html>`__).
74
+
# raises error if request is invalid
75
+
result = unmarshal_request(request, spec=spec)
84
76
85
-
(For OpenAPI v3.1) Use the same function to validate webhook request against a given spec.
77
+
Retrieve validated and unmarshalled request data
86
78
87
79
.. code-block:: python
88
80
89
-
# raise error if request is invalid
90
-
result = validate_request(webhook_request, spec=spec)
91
-
92
-
Webhook request object should implement OpenAPI WebhookRequest protocol (See `Integrations <https://openapi-core.readthedocs.io/en/latest/integrations.html>`__).
93
-
94
-
Retrieve request data from validation result
95
-
96
-
.. code-block:: python
97
-
98
-
# get parameters object with path, query, cookies and headers parameters
99
-
validated_params = result.parameters
100
-
# or specific parameters
101
-
validated_path_params = result.parameters.path
102
-
81
+
# get parameters
82
+
path_params = result.parameters.path
83
+
query_params = result.parameters.query
84
+
cookies_params = result.parameters.cookies
85
+
headers_params = result.parameters.headers
103
86
# get body
104
-
validated_body = result.body
105
-
87
+
body = result.body
106
88
# get security data
107
-
validated_security = result.security
108
-
109
-
Response
110
-
********
89
+
security = result.security
111
90
112
-
Use ``validate_response`` function to validate response against a given spec.
91
+
Request object should implement OpenAPI Request protocol. Check `Integrations <https://openapi-core.readthedocs.io/en/latest/integrations.html>`__ to find oficially supported implementations.
113
92
114
-
.. code-block:: python
93
+
For more details read about `Unmarshalling <https://openapi-core.readthedocs.io/en/latest/unmarshalling.html>`__ process.
115
94
116
-
from openapi_core import validate_response
95
+
If you just want to validate your request/response data without unmarshalling, read about `Validation <https://openapi-core.readthedocs.io/en/latest/validation.html>`__ instead.
117
96
118
-
# raise error if response is invalid
119
-
result = validate_response(request, response, spec=spec)
120
97
121
-
Response object should implement OpenAPI Response protocol (See `Integrations <https://openapi-core.readthedocs.io/en/latest/integrations.html>`__).
98
+
License
99
+
#######
122
100
123
-
(For OpenAPI v3.1) Use the same function to validate response from webhook request against a given spec.
101
+
The project is under the terms of BSD 3-Clause License.
124
102
125
-
.. code-block:: python
126
-
127
-
# raise error if request is invalid
128
-
result = validate_response(webhook_request, response, spec=spec)
129
-
130
-
Retrieve response data from validation result
131
-
132
-
.. code-block:: python
133
-
134
-
# get headers
135
-
validated_headers = result.headers
136
-
137
-
# get data
138
-
validated_data = result.data
139
-
140
-
In order to explicitly validate a:
141
-
142
-
* OpenAPI 3.0 spec, import ``V30RequestValidator`` or ``V30ResponseValidator``
143
-
* OpenAPI 3.1 spec, import ``V31RequestValidator`` or ``V31ResponseValidator`` or ``V31WebhookRequestValidator`` or ``V31WebhookResponseValidator``
144
-
145
-
.. code:: python
146
-
147
-
from openapi_core import V31ResponseValidator
148
-
149
-
result = validate_response(request, response, spec=spec, cls=V31ResponseValidator)
150
-
151
-
You can also explicitly import ``V3RequestValidator`` or ``V3ResponseValidator`` which is a shortcut to the latest v3 release.
Python library that validates OpenAPI Specs against the OpenAPI 2.0 (aka Swagger)and OpenAPI 3.0 specification
107
+
Python library that validates OpenAPI Specs against the OpenAPI 2.0 (aka Swagger), OpenAPI 3.0 and OpenAPI 3.1 specification. The validator aims to check for full compliance with the Specification.
Firstly, thank you all for taking the time to contribute.
5
+
6
+
The following section describes how you can contribute to the openapi-core project on GitHub.
7
+
8
+
Reporting bugs
9
+
--------------
10
+
11
+
Before you report
12
+
^^^^^^^^^^^^^^^^^
13
+
14
+
* Check whether your issue does not already exist in the `Issue tracker <https://github.com/p1c2u/openapi-core/issues>`__.
15
+
* Make sure it is not a support request or question better suited for `Discussion board <https://github.com/p1c2u/openapi-core/discussions>`__.
16
+
17
+
How to submit a report
18
+
^^^^^^^^^^^^^^^^^^^^^^
19
+
20
+
* Include clear title.
21
+
* Describe your runtime environment with exact versions you use.
22
+
* Describe the exact steps which reproduce the problem, including minimal code snippets.
23
+
* Describe the behavior you observed after following the steps, pasting console outputs.
24
+
* Describe expected behavior to see and why, including links to documentations.
25
+
26
+
Code contribution
27
+
-----------------
28
+
29
+
Prerequisites
30
+
^^^^^^^^^^^^^
31
+
32
+
Install `Poetry <https://python-poetry.org>`__ by following the `official installation instructions <https://python-poetry.org/docs/#installation>`__. Optionally (but recommended), configure Poetry to create a virtual environment in a folder named ``.venv`` within the root directory of the project:
33
+
34
+
.. code-block:: console
35
+
36
+
poetry config virtualenvs.in-project true
37
+
38
+
Setup
39
+
^^^^^
40
+
41
+
To create a development environment and install the runtime and development dependencies, run:
42
+
43
+
.. code-block:: console
44
+
45
+
poetry install
46
+
47
+
Then enter the virtual environment created by Poetry:
48
+
49
+
.. code-block:: console
50
+
51
+
poetry shell
52
+
53
+
Static checks
54
+
^^^^^^^^^^^^^
55
+
56
+
The project uses static checks using fantastic `pre-commit <https://pre-commit.com/>`__. Every change is checked on CI and if it does not pass the tests it cannot be accepted. If you want to check locally then run following command to install pre-commit.
57
+
58
+
To turn on pre-commit checks for commit operations in git, enter:
59
+
60
+
.. code-block:: console
61
+
62
+
pre-commit install
63
+
64
+
To run all checks on your staged files, enter:
65
+
66
+
.. code-block:: console
67
+
68
+
pre-commit run
69
+
70
+
To run all checks on all files, enter:
71
+
72
+
.. code-block:: console
73
+
74
+
pre-commit run --all-files
75
+
76
+
Pre-commit check results are also attached to your PR through integration with Github Action.
0 commit comments