diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..d4f5c62d --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,15 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "pip" + directory: "/" + schedule: + interval: "daily" + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "daily" diff --git a/.github/workflows/python-publish.yml b/.github/workflows/python-publish.yml index b6082213..a5531388 100644 --- a/.github/workflows/python-publish.yml +++ b/.github/workflows/python-publish.yml @@ -18,7 +18,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4.1.0 with: python-version: ${{ matrix.python-version }} - name: Install dependencies diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 9d22fb30..fe15f190 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -18,7 +18,7 @@ jobs: steps: - uses: actions/checkout@v2 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v4.1.0 with: python-version: ${{ matrix.python-version }} - name: Install dependencies diff --git a/openapi_core/contrib/django/requests.py b/openapi_core/contrib/django/requests.py index ace403ea..0337ea8a 100644 --- a/openapi_core/contrib/django/requests.py +++ b/openapi_core/contrib/django/requests.py @@ -36,6 +36,11 @@ def create(cls, request): else: route = cls.path_regex.sub( r'{\1}', request.resolver_match.route) + # Delete start marker and expression marker to allow concatenation. + if route[:1] == "^": + route = route[1:] + if route[-1:] == "$": + route = route[:-1] path_pattern = '/' + route path = request.resolver_match and request.resolver_match.kwargs or {} diff --git a/tests/integration/contrib/django/data/djangoproject/settings.py b/tests/integration/contrib/django/data/djangoproject/settings.py index 1c16bcf6..61305bc8 100644 --- a/tests/integration/contrib/django/data/djangoproject/settings.py +++ b/tests/integration/contrib/django/data/djangoproject/settings.py @@ -50,7 +50,7 @@ 'django.middleware.clickjacking.XFrameOptionsMiddleware', ] -ROOT_URLCONF = 'djangotest.urls' +ROOT_URLCONF = 'djangoproject.urls' TEMPLATES = [ { diff --git a/tests/integration/contrib/django/data/djangoproject/testapp/views.py b/tests/integration/contrib/django/data/djangoproject/testapp/views.py index e28a80af..af466eef 100644 --- a/tests/integration/contrib/django/data/djangoproject/testapp/views.py +++ b/tests/integration/contrib/django/data/djangoproject/testapp/views.py @@ -14,10 +14,10 @@ class TestView(APIView): - def get(self, request, pk): + def get(self, request, pk=None): with open(settings.OPENAPI_SPEC_PATH) as file: spec_yaml = file.read() - spec_dict = yaml.load(spec_yaml) + spec_dict = yaml.safe_load(spec_yaml) spec = create_spec(spec_dict) openapi_request = DjangoOpenAPIRequest(request) diff --git a/tests/integration/contrib/django/data/djangoproject/urls.py b/tests/integration/contrib/django/data/djangoproject/urls.py index 09dfd99f..902330d4 100644 --- a/tests/integration/contrib/django/data/djangoproject/urls.py +++ b/tests/integration/contrib/django/data/djangoproject/urls.py @@ -14,8 +14,8 @@ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import include, path -from djangotest.testapp import views +from django.urls import include, path, re_path +from djangoproject.testapp import views urlpatterns = [ path('admin/', admin.site.urls), @@ -28,4 +28,5 @@ views.TestView.as_view(), name='test', ), + re_path(r"^api/test-regexp/$", views.TestView.as_view()), ] diff --git a/tests/integration/contrib/django/data/openapi.yaml b/tests/integration/contrib/django/data/openapi.yaml index 58c8ec57..3432f2f1 100644 --- a/tests/integration/contrib/django/data/openapi.yaml +++ b/tests/integration/contrib/django/data/openapi.yaml @@ -30,3 +30,13 @@ paths: schema: type: integer minimum: 1 + + /api/test-simple/: + get: + responses: + '200': + description: Success. + content: + application/json: + schema: + type: object diff --git a/tests/integration/contrib/django/test_django_core_apiview.py b/tests/integration/contrib/django/test_django_core_apiview.py new file mode 100644 index 00000000..5403caf8 --- /dev/null +++ b/tests/integration/contrib/django/test_django_core_apiview.py @@ -0,0 +1,16 @@ +import pytest + +from six import b + + +class TestDjangoRESTFrameworkAPIView(object): + + @pytest.fixture + def http_client(self): + from django.test import Client + return Client() + + def test_get(self, http_client): + response = http_client.get('/api/test-simple/') + + assert response.content == b('{"test": "test_val"}')