drf_openapi icon indicating copy to clipboard operation
drf_openapi copied to clipboard

Using the Django 2.0 path function for routes results in backslash escaped paths in OpenAPI output

Open pansapiens opened this issue 8 years ago • 0 comments

  • DRF OpenAPI version: 1.1.0
  • Python version: 3.6.2
  • Operating System: macOS 10.13.1

Description

I updated some Django 1.x code to Django 2.0 and changed a number of url routes to the new-style path function ( https://docs.djangoproject.com/en/2.0/ref/urls/#path ). The Swagger HTML output and OpenAPI JSON (?format=openapi) output now contains 'backslash escaped' forward slashes, like /v2.0\/schema\/ instead of the expected /v2.0/schema/.

What I Did

You can reproduce the issue from the drf_openapi/example by changing urls.py to:

from django.urls import path, re_path
from django.conf.urls import include
from django.contrib import admin

from examples.views import MySchemaView

API_PREFIX = r'^(?P<version>[0-9]+\.[0-9]+)'

urlpatterns = [
    re_path(r'^admin/', admin.site.urls),
    path(f'<str:version>/schema/', MySchemaView.as_view(), name='api_schema'),
    re_path(f'{API_PREFIX}/snippets/', include('snippets.urls')),
]

This uses the new Django 2.x path function for routes as an example.

screen shot 2017-12-18 at 2 51 42 pm

pansapiens avatar Dec 18 '17 03:12 pansapiens