Skip to content

Commit 4005f78

Browse files
committed
#296: Adds support for OpenAPI 3.1
1 parent 51fa9cd commit 4005f78

28 files changed

+454
-65
lines changed

.github/workflows/python-test.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
uses: actions/setup-python@v2
2424
with:
2525
python-version: ${{ matrix.python-version }}
26-
26+
2727
- name: Get full Python version
2828
id: full-python-version
2929
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ nosetests.xml
4646
coverage.xml
4747
*.cover
4848
.hypothesis/
49+
tests/**/reports
4950

5051
# Translations
5152
*.mo
@@ -104,4 +105,4 @@ ENV/
104105
# Jetbrains project files
105106
.idea/
106107

107-
/reports/
108+
/reports/

openapi_core/spec/shortcuts.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ def create_spec(
1111
spec_dict,
1212
spec_url="",
1313
handlers=default_handlers,
14+
spec_validator=openapi_v3_spec_validator,
1415
validate_spec=True,
1516
):
1617
if validate_spec:
17-
openapi_v3_spec_validator.validate(spec_dict, spec_url=spec_url)
18+
spec_validator.validate(spec_dict, spec_url=spec_url)
1819

1920
spec_resolver = RefResolver(spec_url, spec_dict, handlers=handlers)
2021
dereferencer = Dereferencer(spec_resolver)

poetry.lock

+31-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ flask = {version = "*", optional = true}
4141
isodate = "*"
4242
more-itertools = "*"
4343
parse = "*"
44-
openapi-schema-validator = "^0.2.0"
45-
openapi-spec-validator = "^0.4.0"
44+
openapi-schema-validator = {version = "0.3.0a1", allow-prereleases = true}
45+
openapi-spec-validator = {version = "0.5.0a1", allow-prereleases = true}
4646
requests = {version = "*", optional = true}
4747
werkzeug = "*"
4848

tests/integration/contrib/django/data/v3.0/djangoproject/settings.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from pathlib import Path
1515

1616
import yaml
17+
from openapi_spec_validator import openapi_v30_spec_validator
1718

1819
from openapi_core import create_spec
1920

@@ -123,4 +124,6 @@
123124

124125
OPENAPI_SPEC_DICT = yaml.load(OPENAPI_SPEC_PATH.read_text(), yaml.Loader)
125126

126-
OPENAPI_SPEC = create_spec(OPENAPI_SPEC_DICT)
127+
OPENAPI_SPEC = create_spec(
128+
OPENAPI_SPEC_DICT, spec_validator=openapi_v30_spec_validator
129+
)
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
from pathlib import Path
22

33
import yaml
4+
from openapi_spec_validator import openapi_v30_spec_validator
45

56
from openapi_core import create_spec
67
from openapi_core.contrib.falcon.middlewares import FalconOpenAPIMiddleware
78

89
openapi_spec_path = Path("tests/integration/data/v3.0/petstore.yaml")
910
spec_dict = yaml.load(openapi_spec_path.read_text(), yaml.Loader)
10-
spec = create_spec(spec_dict)
11+
spec = create_spec(spec_dict, spec_validator=openapi_v30_spec_validator)
1112
openapi_middleware = FalconOpenAPIMiddleware.from_spec(spec)

tests/integration/contrib/flask/test_flask_decorator.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from flask import Flask
33
from flask import jsonify
44
from flask import make_response
5+
from openapi_spec_validator import openapi_v30_spec_validator
56

67
from openapi_core.contrib.flask.decorators import FlaskOpenAPIViewDecorator
78
from openapi_core.shortcuts import create_spec
@@ -15,7 +16,10 @@ class TestFlaskOpenAPIDecorator:
1516
@pytest.fixture
1617
def spec(self, factory):
1718
specfile = "contrib/flask/data/v3.0/flask_factory.yaml"
18-
return create_spec(factory.spec_from_file(specfile))
19+
return create_spec(
20+
factory.spec_from_file(specfile),
21+
spec_validator=openapi_v30_spec_validator,
22+
)
1923

2024
@pytest.fixture
2125
def decorator(self, spec):

tests/integration/contrib/flask/test_flask_validation.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pytest
2+
from openapi_spec_validator import openapi_v30_spec_validator
23

34
from openapi_core.contrib.flask import FlaskOpenAPIRequest
45
from openapi_core.contrib.flask import FlaskOpenAPIResponse
@@ -11,7 +12,10 @@ class TestFlaskOpenAPIValidation:
1112
@pytest.fixture
1213
def flask_spec(self, factory):
1314
specfile = "contrib/flask/data/v3.0/flask_factory.yaml"
14-
return create_spec(factory.spec_from_file(specfile))
15+
return create_spec(
16+
factory.spec_from_file(specfile),
17+
spec_validator=openapi_v30_spec_validator,
18+
)
1519

1620
def test_response_validator_path_pattern(
1721
self, flask_spec, request_factory, response_factory

tests/integration/contrib/flask/test_flask_views.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from flask import Flask
33
from flask import jsonify
44
from flask import make_response
5+
from openapi_spec_validator import openapi_v30_spec_validator
56

67
from openapi_core.contrib.flask.views import FlaskOpenAPIView
78
from openapi_core.shortcuts import create_spec
@@ -14,7 +15,10 @@ class TestFlaskOpenAPIView:
1415
@pytest.fixture
1516
def spec(self, factory):
1617
specfile = "contrib/flask/data/v3.0/flask_factory.yaml"
17-
return create_spec(factory.spec_from_file(specfile))
18+
return create_spec(
19+
factory.spec_from_file(specfile),
20+
spec_validator=openapi_v30_spec_validator,
21+
)
1822

1923
@pytest.fixture
2024
def app(self):

tests/integration/contrib/requests/test_requests_validation.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
22
import requests
33
import responses
4+
from openapi_spec_validator import openapi_v30_spec_validator
45

56
from openapi_core.contrib.requests import RequestsOpenAPIRequest
67
from openapi_core.contrib.requests import RequestsOpenAPIResponse
@@ -13,7 +14,10 @@ class TestRequestsOpenAPIValidation:
1314
@pytest.fixture
1415
def spec(self, factory):
1516
specfile = "contrib/requests/data/v3.0/requests_factory.yaml"
16-
return create_spec(factory.spec_from_file(specfile))
17+
return create_spec(
18+
factory.spec_from_file(specfile),
19+
spec_validator=openapi_v30_spec_validator,
20+
)
1721

1822
@responses.activate
1923
def test_response_validator_path_pattern(self, spec):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
openapi: "3.1.0"
2+
info:
3+
title: Basic OpenAPI specification used with test_flask.TestFlaskOpenAPIIValidation
4+
version: "0.1"
5+
servers:
6+
- url: 'http://testserver'
7+
paths:
8+
'/admin/auth/group/{object_id}/':
9+
parameters:
10+
- name: object_id
11+
in: path
12+
required: true
13+
description: the ID of the resource to retrieve
14+
schema:
15+
type: integer
16+
get:
17+
responses:
18+
default:
19+
description: Return the resource.
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
openapi: "3.1.0"
+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
openapi: "3.1.0"
2+
info:
3+
title: Minimal valid OpenAPI specification
4+
version: "0.1"
5+
paths:
6+
/linked/noParam:
7+
get:
8+
operationId: noParOp
9+
responses:
10+
default:
11+
description: the linked result
12+
/linked/withParam:
13+
get:
14+
operationId: paramOp
15+
parameters:
16+
- name: opParam
17+
in: query
18+
description: test
19+
schema:
20+
type: string
21+
responses:
22+
default:
23+
description: the linked result
24+
/status:
25+
get:
26+
responses:
27+
default:
28+
description: Return something
29+
links:
30+
noParamLink:
31+
operationId: noParOp
32+
/status/{resourceId}:
33+
get:
34+
parameters:
35+
- name: resourceId
36+
in: path
37+
required: true
38+
schema:
39+
type: string
40+
responses:
41+
default:
42+
description: Return something else
43+
links:
44+
paramLink:
45+
operationId: paramOp
46+
parameters:
47+
opParam: $request.path.resourceId
48+
requestBody: test
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
openapi: "3.1.0"
2+
info:
3+
title: Minimal valid OpenAPI specification
4+
version: "0.1"
5+
paths:
6+
/status:
7+
get:
8+
responses:
9+
default:
10+
description: Return the API status.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
openapi: "3.1.0"
2+
info:
3+
title: Minimal valid OpenAPI specification with explicit 'servers' array
4+
version: "0.1"
5+
servers:
6+
- url: /
7+
paths:
8+
/status:
9+
get:
10+
responses:
11+
default:
12+
description: Return the API status.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
openapi: "3.1.0"
2+
info:
3+
title: Minimal OpenAPI specification with path parameters
4+
version: "0.1"
5+
paths:
6+
/resource/{resId}:
7+
parameters:
8+
- name: resId
9+
in: path
10+
required: true
11+
description: the ID of the resource to retrieve
12+
schema:
13+
type: string
14+
get:
15+
responses:
16+
default:
17+
description: Return the resource.

0 commit comments

Comments
 (0)