Skip to content

p1c2u/openapi-core#296: Adds support for OpenAPI 3.1 #373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/python-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Get full Python version
id: full-python-version
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ nosetests.xml
coverage.xml
*.cover
.hypothesis/
tests/**/reports

# Translations
*.mo
Expand Down Expand Up @@ -104,4 +105,4 @@ ENV/
# Jetbrains project files
.idea/

/reports/
/reports/
3 changes: 2 additions & 1 deletion openapi_core/spec/shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ def create_spec(
spec_dict,
spec_url="",
handlers=default_handlers,
spec_validator=openapi_v3_spec_validator,
validate_spec=True,
):
if validate_spec:
openapi_v3_spec_validator.validate(spec_dict, spec_url=spec_url)
spec_validator.validate(spec_dict, spec_url=spec_url)

spec_resolver = RefResolver(spec_url, spec_dict, handlers=handlers)
dereferencer = Dereferencer(spec_resolver)
Expand Down
41 changes: 31 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ flask = {version = "*", optional = true}
isodate = "*"
more-itertools = "*"
parse = "*"
openapi-schema-validator = "^0.2.0"
openapi-spec-validator = "^0.4.0"
openapi-schema-validator = {version = "0.3.0a1", allow-prereleases = true}
openapi-spec-validator = {version = "0.5.0a1", allow-prereleases = true}
requests = {version = "*", optional = true}
werkzeug = "*"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from pathlib import Path

import yaml
from openapi_spec_validator import openapi_v30_spec_validator

from openapi_core import create_spec

Expand Down Expand Up @@ -123,4 +124,6 @@

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

OPENAPI_SPEC = create_spec(OPENAPI_SPEC_DICT)
OPENAPI_SPEC = create_spec(
OPENAPI_SPEC_DICT, spec_validator=openapi_v30_spec_validator
)
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
from pathlib import Path

import yaml
from openapi_spec_validator import openapi_v30_spec_validator

from openapi_core import create_spec
from openapi_core.contrib.falcon.middlewares import FalconOpenAPIMiddleware

openapi_spec_path = Path("tests/integration/data/v3.0/petstore.yaml")
spec_dict = yaml.load(openapi_spec_path.read_text(), yaml.Loader)
spec = create_spec(spec_dict)
spec = create_spec(spec_dict, spec_validator=openapi_v30_spec_validator)
openapi_middleware = FalconOpenAPIMiddleware.from_spec(spec)
6 changes: 5 additions & 1 deletion tests/integration/contrib/flask/test_flask_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from flask import Flask
from flask import jsonify
from flask import make_response
from openapi_spec_validator import openapi_v30_spec_validator

from openapi_core.contrib.flask.decorators import FlaskOpenAPIViewDecorator
from openapi_core.shortcuts import create_spec
Expand All @@ -15,7 +16,10 @@ class TestFlaskOpenAPIDecorator:
@pytest.fixture
def spec(self, factory):
specfile = "contrib/flask/data/v3.0/flask_factory.yaml"
return create_spec(factory.spec_from_file(specfile))
return create_spec(
factory.spec_from_file(specfile),
spec_validator=openapi_v30_spec_validator,
)

@pytest.fixture
def decorator(self, spec):
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/contrib/flask/test_flask_validation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest
from openapi_spec_validator import openapi_v30_spec_validator

from openapi_core.contrib.flask import FlaskOpenAPIRequest
from openapi_core.contrib.flask import FlaskOpenAPIResponse
Expand All @@ -11,7 +12,10 @@ class TestFlaskOpenAPIValidation:
@pytest.fixture
def flask_spec(self, factory):
specfile = "contrib/flask/data/v3.0/flask_factory.yaml"
return create_spec(factory.spec_from_file(specfile))
return create_spec(
factory.spec_from_file(specfile),
spec_validator=openapi_v30_spec_validator,
)

def test_response_validator_path_pattern(
self, flask_spec, request_factory, response_factory
Expand Down
6 changes: 5 additions & 1 deletion tests/integration/contrib/flask/test_flask_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from flask import Flask
from flask import jsonify
from flask import make_response
from openapi_spec_validator import openapi_v30_spec_validator

from openapi_core.contrib.flask.views import FlaskOpenAPIView
from openapi_core.shortcuts import create_spec
Expand All @@ -14,7 +15,10 @@ class TestFlaskOpenAPIView:
@pytest.fixture
def spec(self, factory):
specfile = "contrib/flask/data/v3.0/flask_factory.yaml"
return create_spec(factory.spec_from_file(specfile))
return create_spec(
factory.spec_from_file(specfile),
spec_validator=openapi_v30_spec_validator,
)

@pytest.fixture
def app(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest
import requests
import responses
from openapi_spec_validator import openapi_v30_spec_validator

from openapi_core.contrib.requests import RequestsOpenAPIRequest
from openapi_core.contrib.requests import RequestsOpenAPIResponse
Expand All @@ -13,7 +14,10 @@ class TestRequestsOpenAPIValidation:
@pytest.fixture
def spec(self, factory):
specfile = "contrib/requests/data/v3.0/requests_factory.yaml"
return create_spec(factory.spec_from_file(specfile))
return create_spec(
factory.spec_from_file(specfile),
spec_validator=openapi_v30_spec_validator,
)

@responses.activate
def test_response_validator_path_pattern(self, spec):
Expand Down
19 changes: 19 additions & 0 deletions tests/integration/data/v3.1/django_factory.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
openapi: "3.1.0"
info:
title: Basic OpenAPI specification used with test_flask.TestFlaskOpenAPIIValidation
version: "0.1"
servers:
- url: 'http://testserver'
paths:
'/admin/auth/group/{object_id}/':
parameters:
- name: object_id
in: path
required: true
description: the ID of the resource to retrieve
schema:
type: integer
get:
responses:
default:
description: Return the resource.
1 change: 1 addition & 0 deletions tests/integration/data/v3.1/empty.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
openapi: "3.1.0"
48 changes: 48 additions & 0 deletions tests/integration/data/v3.1/links.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
openapi: "3.1.0"
info:
title: Minimal valid OpenAPI specification
version: "0.1"
paths:
/linked/noParam:
get:
operationId: noParOp
responses:
default:
description: the linked result
/linked/withParam:
get:
operationId: paramOp
parameters:
- name: opParam
in: query
description: test
schema:
type: string
responses:
default:
description: the linked result
/status:
get:
responses:
default:
description: Return something
links:
noParamLink:
operationId: noParOp
/status/{resourceId}:
get:
parameters:
- name: resourceId
in: path
required: true
schema:
type: string
responses:
default:
description: Return something else
links:
paramLink:
operationId: paramOp
parameters:
opParam: $request.path.resourceId
requestBody: test
10 changes: 10 additions & 0 deletions tests/integration/data/v3.1/minimal.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
openapi: "3.1.0"
info:
title: Minimal valid OpenAPI specification
version: "0.1"
paths:
/status:
get:
responses:
default:
description: Return the API status.
12 changes: 12 additions & 0 deletions tests/integration/data/v3.1/minimal_with_servers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
openapi: "3.1.0"
info:
title: Minimal valid OpenAPI specification with explicit 'servers' array
version: "0.1"
servers:
- url: /
paths:
/status:
get:
responses:
default:
description: Return the API status.
17 changes: 17 additions & 0 deletions tests/integration/data/v3.1/path_param.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
openapi: "3.1.0"
info:
title: Minimal OpenAPI specification with path parameters
version: "0.1"
paths:
/resource/{resId}:
parameters:
- name: resId
in: path
required: true
description: the ID of the resource to retrieve
schema:
type: string
get:
responses:
default:
description: Return the resource.
Loading