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

Schema structure is not suitable for detail_route or list_route with multiple methods #4391

Closed
6 tasks done
Nnonexistent opened this issue Aug 11, 2016 · 5 comments
Closed
6 tasks done
Labels
Milestone

Comments

@Nnonexistent
Copy link

Nnonexistent commented Aug 11, 2016

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. 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.

@Nnonexistent
Copy link
Author

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.

@tomchristie tomchristie added this to the 3.4.4 Release milestone Aug 11, 2016
@tomchristie
Copy link
Member

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)

@Nnonexistent
Copy link
Author

Nnonexistent commented Aug 14, 2016

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.

@kmmbvnr
Copy link

kmmbvnr commented Aug 29, 2016

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

@Nnonexistent
Copy link
Author

@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.

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

No branches or pull requests

3 participants