Skip to content

Commit b1ec9d8

Browse files
committed
Merge branch 'master' into any-of
2 parents c6dd04b + bf2f13d commit b1ec9d8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+1380
-742
lines changed

.github/workflows/python-test.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010

1111
jobs:
1212
test:
13+
name: "Tests"
1314
runs-on: ubuntu-latest
1415
strategy:
1516
matrix:
@@ -31,3 +32,16 @@ jobs:
3132
run: python setup.py test
3233
- name: Upload coverage
3334
uses: codecov/codecov-action@v1
35+
36+
static-checks:
37+
name: "Static checks"
38+
runs-on: ubuntu-latest
39+
steps:
40+
- name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )"
41+
uses: actions/checkout@v2
42+
- name: "Setup Python"
43+
uses: actions/setup-python@v2
44+
with:
45+
python-version: 3.9
46+
- name: "Run static checks"
47+
uses: pre-commit/[email protected]

.pre-commit-config.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
default_stages: [commit, push]
3+
default_language_version:
4+
# force all unspecified python hooks to run python3
5+
python: python3
6+
minimum_pre_commit_version: "1.20.0"
7+
repos:
8+
- repo: meta
9+
hooks:
10+
- id: check-hooks-apply
11+
- repo: https://github.com/asottile/pyupgrade
12+
rev: v2.19.0
13+
hooks:
14+
- id: pyupgrade
15+
args: ["--py36-plus"]
16+
- repo: local
17+
hooks:
18+
- id: flynt
19+
name: Convert to f-strings with flynt
20+
entry: flynt
21+
language: python
22+
additional_dependencies: ['flynt==0.64']

CONTRIBUTING.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Contributor Guide
3+
=================
4+
5+
# Static checks
6+
7+
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:
8+
9+
```bash
10+
pip install -r requiremenets_dev.txt
11+
```
12+
13+
To turn on pre-commit checks for commit operations in git, enter:
14+
```bash
15+
pre-commit install
16+
```
17+
18+
To run all checks on your staged files, enter:
19+
```bash
20+
pre-commit run
21+
```
22+
23+
To run all checks on all files, enter:
24+
```bash
25+
pre-commit run --all-files
26+
```
27+
28+
Pre-commit check results are also attached to your PR through integration with Github Action.

docs/integrations.rst

Lines changed: 75 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,55 @@ Integrations
44
Bottle
55
------
66

7-
See `bottle-openapi-3 <https://github.com/cope-systems/bottle-openapi-3>`_ project.
7+
See `bottle-openapi-3 <https://github.com/cope-systems/bottle-openapi-3>`_ project.
88

99

1010
Django
1111
------
1212

1313
This section describes integration with `Django <https://www.djangoproject.com>`__ web framework.
14+
The integration supports Django from version 3.0 and above.
1415

15-
For Django 2.2 you can use DjangoOpenAPIRequest a Django request factory:
16+
Middleware
17+
~~~~~~~~~~
18+
19+
Django can be integrated by middleware. Add `DjangoOpenAPIMiddleware` to your `MIDDLEWARE` list and define `OPENAPI_SPEC`.
20+
21+
.. code-block:: python
22+
23+
# settings.py
24+
from openapi_core import create_spec
25+
26+
MIDDLEWARE = [
27+
# ...
28+
'openapi_core.contrib.django.middlewares.DjangoOpenAPIMiddleware',
29+
]
30+
31+
OPENAPI_SPEC = create_spec(spec_dict)
32+
33+
After that you have access to validation result object with all validated request data from Django view through request object.
34+
35+
.. code-block:: python
36+
37+
from django.views import View
38+
39+
class MyView(View):
40+
def get(self, req):
41+
# get parameters object with path, query, cookies and headers parameters
42+
validated_params = req.openapi.parameters
43+
# or specific location parameters
44+
validated_path_params = req.openapi.parameters.path
45+
46+
# get body
47+
validated_body = req.openapi.body
48+
49+
# get security data
50+
validated_security = req.openapi.security
51+
52+
Low level
53+
~~~~~~~~~
54+
55+
You can use `DjangoOpenAPIRequest` as a Django request factory:
1656

1757
.. code-block:: python
1858
@@ -23,7 +63,7 @@ For Django 2.2 you can use DjangoOpenAPIRequest a Django request factory:
2363
validator = RequestValidator(spec)
2464
result = validator.validate(openapi_request)
2565
26-
You can use DjangoOpenAPIResponse as a Django response factory:
66+
You can use `DjangoOpenAPIResponse` as a Django response factory:
2767

2868
.. code-block:: python
2969
@@ -39,41 +79,59 @@ Falcon
3979
------
4080

4181
This section describes integration with `Falcon <https://falconframework.org>`__ web framework.
82+
The integration supports Falcon from version 3.0 and above.
4283

4384
Middleware
4485
~~~~~~~~~~
4586

46-
Falcon API can be integrated by `FalconOpenAPIMiddleware` middleware.
87+
The Falcon API can be integrated by `FalconOpenAPIMiddleware` middleware.
4788

4889
.. code-block:: python
4990
5091
from openapi_core.contrib.falcon.middlewares import FalconOpenAPIMiddleware
5192
5293
openapi_middleware = FalconOpenAPIMiddleware.from_spec(spec)
53-
api = falcon.API(middleware=[openapi_middleware])
94+
app = falcon.App(middleware=[openapi_middleware])
95+
96+
After that you will have access to validation result object with all validated request data from Falcon view through request context.
97+
98+
.. code-block:: python
99+
100+
class ThingsResource:
101+
def on_get(self, req, resp):
102+
# get parameters object with path, query, cookies and headers parameters
103+
validated_params = req.context.openapi.parameters
104+
# or specific location parameters
105+
validated_path_params = req.context.openapi.parameters.path
106+
107+
# get body
108+
validated_body = req.context.openapi.body
109+
110+
# get security data
111+
validated_security = req.context.openapi.security
54112
55113
Low level
56114
~~~~~~~~~
57115

58-
For Falcon you can use FalconOpenAPIRequest a Falcon request factory:
116+
You can use `FalconOpenAPIRequest` as a Falcon request factory:
59117

60118
.. code-block:: python
61119
62120
from openapi_core.validation.request.validators import RequestValidator
63121
from openapi_core.contrib.falcon import FalconOpenAPIRequestFactory
64122
65-
openapi_request = FalconOpenAPIRequestFactory.create(falcon_request)
123+
openapi_request = FalconOpenAPIRequestFactory().create(falcon_request)
66124
validator = RequestValidator(spec)
67125
result = validator.validate(openapi_request)
68126
69-
You can use FalconOpenAPIResponse as a Falcon response factory:
127+
You can use `FalconOpenAPIResponse` as a Falcon response factory:
70128

71129
.. code-block:: python
72130
73131
from openapi_core.validation.response.validators import ResponseValidator
74132
from openapi_core.contrib.falcon import FalconOpenAPIResponseFactory
75133
76-
openapi_response = FalconOpenAPIResponseFactory.create(falcon_response)
134+
openapi_response = FalconOpenAPIResponseFactory().create(falcon_response)
77135
validator = ResponseValidator(spec)
78136
result = validator.validate(openapi_request, openapi_response)
79137
@@ -109,7 +167,7 @@ If you want to decorate class based view you can use the decorators attribute:
109167
View
110168
~~~~
111169

112-
As an alternative to the decorator-based integration, Flask method based views can be integrated by inheritance from `FlaskOpenAPIView` class.
170+
As an alternative to the decorator-based integration, a Flask method based views can be integrated by inheritance from `FlaskOpenAPIView` class.
113171

114172
.. code-block:: python
115173
@@ -123,7 +181,7 @@ As an alternative to the decorator-based integration, Flask method based views c
123181
Request parameters
124182
~~~~~~~~~~~~~~~~~~
125183

126-
In Flask, all unmarshalled request data are provided as Flask request object's openapi.parameters attribute
184+
In Flask, all unmarshalled request data are provided as Flask request object's `openapi.parameters` attribute
127185

128186
.. code-block:: python
129187
@@ -138,7 +196,7 @@ In Flask, all unmarshalled request data are provided as Flask request object's o
138196
Low level
139197
~~~~~~~~~
140198

141-
You can use FlaskOpenAPIRequest a Flask/Werkzeug request factory:
199+
You can use `FlaskOpenAPIRequest` as a Flask/Werkzeug request factory:
142200

143201
.. code-block:: python
144202
@@ -149,7 +207,7 @@ You can use FlaskOpenAPIRequest a Flask/Werkzeug request factory:
149207
validator = RequestValidator(spec)
150208
result = validator.validate(openapi_request)
151209
152-
You can use FlaskOpenAPIResponse as a Flask/Werkzeug response factory:
210+
You can use `FlaskOpenAPIResponse` as a Flask/Werkzeug response factory:
153211

154212
.. code-block:: python
155213
@@ -164,7 +222,7 @@ You can use FlaskOpenAPIResponse as a Flask/Werkzeug response factory:
164222
Pyramid
165223
-------
166224

167-
See `pyramid_openapi3 <https://github.com/niteoweb/pyramid_openapi3>`_ project.
225+
See `pyramid_openapi3 <https://github.com/niteoweb/pyramid_openapi3>`_ project.
168226

169227

170228
Requests
@@ -175,7 +233,7 @@ This section describes integration with `Requests <https://requests.readthedocs.
175233
Low level
176234
~~~~~~~~~
177235

178-
For Requests you can use RequestsOpenAPIRequest a Requests request factory:
236+
You can use `RequestsOpenAPIRequest` as a Requests request factory:
179237

180238
.. code-block:: python
181239
@@ -186,7 +244,7 @@ For Requests you can use RequestsOpenAPIRequest a Requests request factory:
186244
validator = RequestValidator(spec)
187245
result = validator.validate(openapi_request)
188246
189-
You can use RequestsOpenAPIResponse as a Requests response factory:
247+
You can use `RequestsOpenAPIResponse` as a Requests response factory:
190248

191249
.. code-block:: python
192250
@@ -200,4 +258,4 @@ You can use RequestsOpenAPIResponse as a Requests response factory:
200258
Tornado
201259
-------
202260

203-
See `tornado-openapi3 <https://github.com/correl/tornado-openapi3>`_ project.
261+
See `tornado-openapi3 <https://github.com/correl/tornado-openapi3>`_ project.

docs/usage.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ and unmarshal request data from validation result
3838
3939
# get parameters object with path, query, cookies and headers parameters
4040
validated_params = result.parameters
41-
# or specific parameters
41+
# or specific location parameters
4242
validated_path_params = result.parameters.path
4343
4444
# get body

openapi_core/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
# -*- coding: utf-8 -*-
21
"""OpenAPI core module"""
32
from openapi_core.shortcuts import (
43
create_spec, validate_request, validate_response,

openapi_core/casting/schemas/exceptions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ class CastError(OpenAPIError):
1010
type: str
1111

1212
def __str__(self):
13-
return "Failed to cast value to {type} type: {value}".format(
14-
type=self.type, value=self.value)
13+
return f"Failed to cast value to {self.type} type: {self.value}"

openapi_core/contrib/django/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
"""OpenAPI core contrib django module"""
12
from openapi_core.contrib.django.requests import DjangoOpenAPIRequestFactory
23
from openapi_core.contrib.django.responses import DjangoOpenAPIResponseFactory
34

4-
# backward compatibility
5-
DjangoOpenAPIRequest = DjangoOpenAPIRequestFactory.create
6-
DjangoOpenAPIResponse = DjangoOpenAPIResponseFactory.create
5+
DjangoOpenAPIRequest = DjangoOpenAPIRequestFactory().create
6+
DjangoOpenAPIResponse = DjangoOpenAPIResponseFactory().create
77

88
__all__ = [
99
'DjangoOpenAPIRequestFactory', 'DjangoOpenAPIResponseFactory',

openapi_core/contrib/django/backports.py

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

openapi_core/contrib/django/compat.py

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

0 commit comments

Comments
 (0)