Skip to content
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

Handle duplicate urls in urlconf #155

Merged
merged 2 commits into from
Jun 29, 2018
Merged

Conversation

jcushman
Copy link
Contributor

Django resolves urls in order from top to bottom, and only uses the first matching URL found. This can happen for example when overriding one view in an existing app:

    path('accounts/login/', user_views.LoginView.as_view(), name='login'),
    path('accounts/', include('django.contrib.auth.urls')),  # logout, password change, password reset

drf-yasg doesn't follow Django's behavior, and instead uses the last view for a given path+method. This means duplicate URLs are documented incorrectly in the resulting schema.

This PR adds a test to show the correct behavior, and a filter to OpenAPISchemaGenerator.get_api_endpoints to ensure that each path is only included once.

@axnsan12
Copy link
Owner

Awesome, thanks for the catch!

@axnsan12 axnsan12 self-assigned this Jun 29, 2018
@axnsan12 axnsan12 added the bug Bug report/fix label Jun 29, 2018
@axnsan12 axnsan12 merged commit 544d72d into axnsan12:master Jun 29, 2018
@jcushman
Copy link
Contributor Author

Thanks for the test fix and quick merge!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug report/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants