get_schema_view() seems to ignore api prefix

304 views
Skip to first unread message

Christopher Sund

unread,
Jul 18, 2019, 3:49:01 PM7/18/19
to Django REST framework
I have an API using DRF that is using a DefaultRouter and get_schema_view() to create an API schema page. The API is routed under "api/" using

router = DefaultRouter(trailing_slash=False)
...
urlpatterns = [
    path('api/', include(router.urls)),
    ...
]

The generated schema, however does not provide the proper paths that include this prefix e.g. "/get-items" instead of "/api/get-items". Examining the code, it appears SchemaGenerator in openapi.py determines a path prefix in get_paths(). It then determines the subpath of each action by removing the leading prefix, but does not retain the prefix information. I have attempted to set the url and urlconf kwargs in get_schema_view() but they appear to have no effect on the generated schema. As a result of this prefix exclusion, tools that make use of the generated schema, e.g. SwaggerUI do not use the proper API endpoints. Is there something I'm missing with respect to schema generation including this prefix?

Carlton Gibson

unread,
Jul 18, 2019, 3:55:24 PM7/18/19
to django-res...@googlegroups.com
The `url` parameter is meant to set the base url, so assuming you’re passing this, it could be a bug. 

Can you open an issue with full details: 


(A PR adding a test case for this would be awesome, if you’re up for that.) 

If we can verify, I would imagine it’d be an easy enough fix. (😬)

Thanks! 

Kind Regards,

Carlton


--
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-rest-framework/b3d593e2-ce60-4ad0-ad84-e9243b981ed0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christopher Sund

unread,
Jul 18, 2019, 3:55:43 PM7/18/19
to Django REST framework
On the DRF github it appears there is an open Issue #6675 that also discusses this problem

Carlton Gibson

unread,
Jul 18, 2019, 3:57:55 PM7/18/19
to django-res...@googlegroups.com
Grrr. That totally missed my radar. (Life.) 

OK, thanks I’ll have a look at that. 

(PRs with test cases still welcome 🙂)

-- 
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-fram...@googlegroups.com.

Carlton Gibson

unread,
Jul 18, 2019, 4:08:58 PM7/18/19
to django-res...@googlegroups.com
Hi Christopher, 

Reading #6675, I’m not entirely convinced it’s the same issue. (Related, sure.) 

Could you open a ticket with your exact case as well please? I’d rather close it as a duplicate than miss a second case. 

Thanks. 

Kind Regards,

Carlton

Christopher Sund

unread,
Jul 18, 2019, 4:44:17 PM7/18/19
to Django REST framework
I have posted an issue (#6823) and included a minimal example. I don't currently have time to create a pull request today, but I can probably start working on a simple test case tomorrow.


On Thursday, July 18, 2019 at 1:08:58 PM UTC-7, Carlton Gibson wrote:
Hi Christopher, 

Reading #6675, I’m not entirely convinced it’s the same issue. (Related, sure.) 

Could you open a ticket with your exact case as well please? I’d rather close it as a duplicate than miss a second case. 

Thanks. 

Kind Regards,

Carlton


On 18 Jul 2019, at 21:57, Carlton Gibson <carlto...@gmail.com> wrote:

Grrr. That totally missed my radar. (Life.) 

OK, thanks I’ll have a look at that. 

(PRs with test cases still welcome 🙂)
On 18 Jul 2019, at 21:55, Christopher Sund <csun...@gmail.com> wrote:

On the DRF github it appears there is an open Issue #6675 that also discusses this problem

On Thursday, July 18, 2019 at 12:49:01 PM UTC-7, Christopher Sund wrote:
I have an API using DRF that is using a DefaultRouter and get_schema_view() to create an API schema page. The API is routed under "api/" using 

router = DefaultRouter(trailing_slash=False)
...
urlpatterns = [
    path('api/', include(router.urls)),
    ...
]

The generated schema, however does not provide the proper paths that include this prefix e.g. "/get-items" instead of "/api/get-items". Examining the code, it appears SchemaGenerator in openapi.py determines a path prefix in get_paths(). It then determines the subpath of each action by removing the leading prefix, but does not retain the prefix information. I have attempted to set the url and urlconf kwargs in get_schema_view() but they appear to have no effect on the generated schema. As a result of this prefix exclusion, tools that make use of the generated schema, e.g. SwaggerUI do not use the proper API endpoints. Is there something I'm missing with respect to schema generation including this prefix?

-- 
You received this message because you are subscribed to the Google Groups "Django REST framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-rest-framework+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages