Skip to content

Commit dd36ada

Browse files
authored
Merge pull request #516 from p1c2u/feature/documentation-improvements
documentation improvements
2 parents 25bc5f0 + 6b00be5 commit dd36ada

13 files changed

+463
-324
lines changed

CONTRIBUTING.md

Lines changed: 0 additions & 47 deletions
This file was deleted.

CONTRIBUTING.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Please read the `Contributing <https://openapi-core.readthedocs.io/en/latest/unmarshalling.html>`__ guidelines in the documentation site.

README.rst

Lines changed: 34 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ Openapi-core is a Python library that adds client-side and server-side support
2222
for the `OpenAPI v3.0 <https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.3.md>`__
2323
and `OpenAPI v3.1 <https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md>`__ specification.
2424

25+
2526
Key features
26-
************
27+
############
2728

28-
* **Validation** of requests and responses
29-
* Schema **casting** and **unmarshalling**
30-
* Media type and parameters **deserialization**
31-
* **Security** providers (API keys, Cookie, Basic and Bearer HTTP authentications)
32-
* Custom **deserializers** and **formats**
33-
* **Integration** with libraries and frameworks
29+
* **Validation** and **unmarshalling** of request and response data (including webhooks)
30+
* **Integration** with popular libraries (Requests, Werkzeug) and frameworks (Django, Falcon, Flask, Starlette)
31+
* Customization with media type **deserializers** and format **unmarshallers**
32+
* **Security** data providers (API keys, Cookie, Basic and Bearer HTTP authentications)
3433

3534

3635
Documentation
@@ -44,19 +43,19 @@ Installation
4443

4544
Recommended way (via pip):
4645

47-
::
46+
.. code-block:: console
4847
49-
$ pip install openapi-core
48+
pip install openapi-core
5049
5150
Alternatively you can download the code and install from the repository:
5251

53-
.. code-block:: bash
52+
.. code-block:: console
5453
55-
$ pip install -e git+https://github.com/p1c2u/openapi-core.git#egg=openapi_core
54+
pip install -e git+https://github.com/p1c2u/openapi-core.git#egg=openapi_core
5655
5756
58-
Usage
59-
#####
57+
First steps
58+
###########
6059

6160
Firstly create your specification object.
6261

@@ -66,98 +65,50 @@ Firstly create your specification object.
6665
6766
spec = Spec.from_file_path('openapi.json')
6867
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.
7569

7670
.. code-block:: python
7771
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
8273
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)
8476
85-
(For OpenAPI v3.1) Use the same function to validate webhook request against a given spec.
77+
Retrieve validated and unmarshalled request data
8678

8779
.. code-block:: python
8880
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
10386
# get body
104-
validated_body = result.body
105-
87+
body = result.body
10688
# get security data
107-
validated_security = result.security
108-
109-
Response
110-
********
89+
security = result.security
11190
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.
11392

114-
.. code-block:: python
93+
For more details read about `Unmarshalling <https://openapi-core.readthedocs.io/en/latest/unmarshalling.html>`__ process.
11594

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.
11796

118-
# raise error if response is invalid
119-
result = validate_response(request, response, spec=spec)
12097

121-
Response object should implement OpenAPI Response protocol (See `Integrations <https://openapi-core.readthedocs.io/en/latest/integrations.html>`__).
98+
License
99+
#######
122100

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.
124102

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.
152103

153104
Related projects
154105
################
155-
* `bottle-openapi-3 <https://github.com/cope-systems/bottle-openapi-3>`__
156-
OpenAPI 3.0 Support for the Bottle Web Framework
157106
* `openapi-spec-validator <https://github.com/p1c2u/openapi-spec-validator>`__
158-
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.
159108
* `openapi-schema-validator <https://github.com/p1c2u/openapi-schema-validator>`__
160-
Python library that validates schema against the OpenAPI Schema Specification v3.0.
109+
Python library that validates schema against the OpenAPI Schema Specification v3.0 and OpenAPI Schema Specification v3.1.
110+
* `bottle-openapi-3 <https://github.com/cope-systems/bottle-openapi-3>`__
111+
OpenAPI 3.0 Support for the Bottle Web Framework
161112
* `pyramid_openapi3 <https://github.com/niteoweb/pyramid_openapi3>`__
162113
Pyramid addon for OpenAPI3 validation of requests and responses.
163114
* `tornado-openapi3 <https://github.com/correl/tornado-openapi3>`__

docs/conf.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,10 @@
6666

6767
# Material theme options (see theme.conf for more information)
6868
html_theme_options = {
69-
# Set you GA account ID to enable tracking
70-
# 'google_analytics_account': 'UA-XXXXX',
71-
# Specify a base_url used to generate sitemap.xml. If not
72-
# specified, then no sitemap will be built.
73-
#'base_url': 'https://project.github.io/project',
74-
# Set the color and the accent color
75-
# Set the repo location to get a badge with stats
69+
"analytics": {
70+
"provider": "google",
71+
"property": "G-J6T05Z51NY",
72+
},
7673
"repo_url": "https://github.com/p1c2u/openapi-core/",
7774
"repo_name": "openapi-core",
7875
"repo_type": "github",

docs/contributing.rst

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
Contributing
2+
============
3+
4+
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.

docs/customizations.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Customizations
22
==============
33

4-
Spec validation
5-
---------------
4+
Specification validation
5+
------------------------
66

77
By default, the provided specification is validated on ``Spec`` object creation time.
88

@@ -62,7 +62,7 @@ Here's how you could add support for a ``usdate`` format that handles dates of t
6262
'usdate': validate_usdate,
6363
}
6464
65-
result = validate_response(
65+
validate_response(
6666
request, response,
6767
spec=spec,
6868
extra_format_validators=extra_format_validators,

0 commit comments

Comments
 (0)