Skip to content

AutoSchema fails when set on detail_route #5630

@axnsan12

Description

@axnsan12

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

  1. 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
  1. Register the view with a router
        router = routers.SimpleRouter()
        router.register(r'detail', AViewSet, base_name='detail')
        routes = router.urls
  1. 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'

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions