Django-rest-framework: Schema structure is not suitable for detail_route or list_route with multiple methods

Created on 11 Aug 2016  路  5Comments  路  Source: encode/django-rest-framework

Checklist

  • [x] I have verified that that issue exists against the master branch of Django REST framework.
  • [x] I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • [x] This is not a usage question. (Those should be directed to the discussion group instead.)
  • [x] 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.)
  • [x] I have reduced the issue to the simplest possible case.
  • [x] 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. Define ViewSet with detail_route method with at least two http methods:
class ExampleViewSet(ModelViewSet):
    @detail_route(methods=['put', 'post'])
    def custom_action(self, request, pk):
        pass
  1. Generate schema:
        schema_generator = SchemaGenerator(title='Restrictive API')
        schema = schema_generator.get_schema()

Expected behavior

Both PUT and POST methods in resulted schema.

Actual behavior

Only one method in generated schema.

Bug

Most helpful comment

It's not fixed. Coreapi document generated by schema generator still use dict with actions as keys and coreapi links as value. So in case of multiple http methods per action it didn't fit in schema.

Test case provided.

All 5 comments

Problem is that in suggested coreapi document structure used dict with actions as values and links as values.

It could be solved by changing action key in schema document for detail_view methods. Or by using list of links as values. I myself don't see full problem scope - just my minor issue.
And such changes could lead to major consequences - so it's up to author to decide.

We're constrained to 2 levels deep if we want to support swagger, so category/action.
But yup I'm looking at this for the 3.4.4 release (final remaining issue)

It's not fixed. Coreapi document generated by schema generator still use dict with actions as keys and coreapi links as value. So in case of multiple http methods per action it didn't fit in schema.

Test case provided.

I also happens if you have 2 similar actions. ex:

class ExampleViewSet1(ModelViewSet):
    @detail_route(methods=['post'])
    def custom_action(self, request, pk):
        pass

class ExampleViewSet2(ModelViewSet):
    @detail_route(methods=['post'])
    def custom_action(self, request, pk):
        pass

@kmmbvnr I was unable to reproduce your case. Even write a simple test for it - see #4400 tests.test_schemas.TestSchemaGenerator.test_similar_actions
Please provide more info on how you register viewsets in urlconf, what serializers/models used etc.

Was this page helpful?
0 / 5 - 0 ratings