AutoSchema fails when set on detail_route · Issue #5630 · encode/django-rest-framework (original) (raw)
Checklist
- I have verified that that issue exists against the
master
branch of Django REST framework. - I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
- This is not a usage question. (Those should be directed to the discussion group instead.)
- This cannot be dealt with as a third party library. (We prefer new functionality to be in the form of third party libraries where possible.)
- I have reduced the issue to the simplest possible case.
- I have included a failing test as a pull request. (If you are unable to do so we can still accept the issue.)
Steps to reproduce
- Create a view with a detail_route with a schema kwarg
class AViewSet(GenericViewSet):
@detail_route(schema=AutoSchema(manual_fields=[
coreapi.Field(
"my_extra_field",
required=True,
location="path",
schema=coreschema.String()
),
]))
def a_detail_route(self, request, my_normal_field):
pass
- Register the view with a router
router = routers.SimpleRouter()
router.register(r'detail', AViewSet, base_name='detail')
routes = router.urls
- Attempt to generate a schema from the view
callback = routes[0].callback
generator = SchemaGenerator()
view = generator.create_view(callback, 'GET')
link = view.schema.get_link('/a/url/{id}/', 'GET', '')
Expected behavior
A schema is generated for the detail route using the given AutoSchema.
Actual behavior
Crashes:AttributeError: 'AutoSchema' object has no attribute '_view'