From f52953d298e2fb87e6247e9411c2a884322f8bd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Bregu=C5=82a?= Date: Sat, 22 May 2021 00:06:09 +0200 Subject: [PATCH 1/4] Support basic re_path --- openapi_core/contrib/django/requests.py | 5 +++++ .../django/data/djangoproject/settings.py | 2 +- .../django/data/djangoproject/testapp/views.py | 4 ++-- .../contrib/django/data/djangoproject/urls.py | 5 +++-- .../integration/contrib/django/data/openapi.yaml | 10 ++++++++++ .../contrib/django/test_django_core_apiview.py | 16 ++++++++++++++++ 6 files changed, 37 insertions(+), 5 deletions(-) create mode 100644 tests/integration/contrib/django/test_django_core_apiview.py 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"}') From b1e2ae51ef8eaa88f77d3d3b5e876c2d428dc6c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Bregu=C5=82a?= Date: Sun, 6 Jun 2021 13:15:39 +0200 Subject: [PATCH 2/4] Create dependabot.yml --- .github/dependabot.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..d46e19c4 --- /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: "python" + directory: "/" + schedule: + interval: "daily" + - package-ecosystem: "github-action" + directory: "/" + schedule: + interval: "daily" From 2399b73ca9ab8c722c879b3121285acff617c619 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Bregu=C5=82a?= Date: Sun, 6 Jun 2021 13:17:04 +0200 Subject: [PATCH 3/4] Update dependabot.yml --- .github/dependabot.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index d46e19c4..d4f5c62d 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -5,11 +5,11 @@ version: 2 updates: - - package-ecosystem: "python" + - package-ecosystem: "pip" directory: "/" schedule: interval: "daily" - - package-ecosystem: "github-action" + - package-ecosystem: "github-actions" directory: "/" schedule: interval: "daily" From 2c827ee66666cdbd329a4c098301110a54e6250a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sun, 6 Jun 2021 11:17:38 +0000 Subject: [PATCH 4/4] Bump parse from 1.14.0 to 1.19.0 Bumps [parse](https://github.com/r1chardj0n3s/parse) from 1.14.0 to 1.19.0. - [Release notes](https://github.com/r1chardj0n3s/parse/releases) - [Commits](https://github.com/r1chardj0n3s/parse/commits/1.19.0) --- updated-dependencies: - dependency-name: parse dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index b2d723d3..dfa51ba8 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,5 +5,5 @@ openapi-schema-validator six lazy-object-proxy attrs -parse==1.14.0 +parse==1.19.0 more-itertools>=5.0.0