-
Notifications
You must be signed in to change notification settings - Fork 602
Group list_route with viewset base path #515
Comments
@marcgibbons I have done this: (with the invaluable help of @cyncyncyn), doing a class that extends from OpenAPIRenderer and writing our own add_customizations method, I think I can export this and alphabetically order (#512) in a way that works on this project with a setting or something, let me know if you would like to have a PR or if it's done now |
@vladimirnani The grouping of URLs is done outside this project. The grouping (known as tags in Swagger) is converted from CoreAPI document links, and is generated by Django REST Framework. This his how the encoder works from CoreAPI to OpenAPI formats: I'd be interested in knowing how your endpoints are grouped as CoreJSON - we can identify if this is a DRF thing, or something on the OpenAPI codec. @angvp Saw your message. I'm about to release some basic SwaggerUI customizations (i.e. sorting, etc.) which ship out of the box with Swagger for v2.0.4. The more "schema" based overrides I think are best if they are upstream (i.e. in DRF / CoreAPI documents) |
@marcgibbons Ok, so tagging is not following a good logic IMO, is just taking the last part of the url, instead of the first part, and it uses that as a "tag". I've tried to understand the logic of python-openapi-codec and DRF and I gave up after failing at several attempts, so I just did this in OpenAPIRenderer. Also naming of the methods it's just awful, and it's "corrected" in a way that works better for my purposes.. You can use the code below @vladimirnani while we wait @tomchristie's input on this issue (though he wasn't aware of it until this mention)
And then use this class instead OpenAPIRenderer on the decorators of schema_view |
@angvp As for the overrides, this doesn't belong here. The CoreAPI is generated in the schema generator and is grouped here: https://github.com/tomchristie/django-rest-framework/blob/master/rest_framework/schemas.py#L187. I think what's needed here is to remove anything from the path that is common to all the patterns (i.e. /api/v1/) before grouping. Otherwise, /api/ could potentially be considered a category / tag. |
@marcgibbons right, it seems that all list_route are considered "new tags" while detail_route is grouped correctly. Ok will try to play around with schema. |
@vladimirnani Can you confirm against 3.4.4. Believe this was resolved in encode/django-rest-framework#4394 |
@tomchristie I am using 3.4.4 and still doesn't work, even without the ugly hack on add_customizations ^ (which btw grew up a little bit more cause some endpoints were from ListCreateAPIView were returning a list with just post method -and not get method-). |
Do you mean The In 3.4.4 we use |
@tomchristie Oh, sorry for the confusion, when I said add_customizations I was referring to the one that I wrote for achieving this (see 4th comment on the thread). And with 3.4.3 the get_category method is still producing this issue .. I will try to create a sample project similar that the one that I have in order to see where's the issue and how to improve all the projects. |
Presume you meant 3.4.4 here, right?
That's great thanks. If you're able to replicate the issue in the existing test suite that'd certainly drive resolution of this forward. |
@tomchristie 3.4.4 resolved, all list_routes are grouped. Thanks!!! |
Ehh not for me. Please do not close this @marcgibbons . This is how it should be seen. And I get that splitted like this: Is that the intended behaviour @tomchristie ? because that kind of grouping to me seems wrong. |
@angvp - I don't think the style you're showing there is not how the default routers/viewsets would generate the URLs? Normally I'd expect to see, this...
I do believe that we may still have some improvements to make for correctly generating tags against plain views and URLs, but believe that we'd still be generating the second style, rather than the first. (No clear way from that URL style to determine exactly which of the two you'd be expecting) You may want to customize the |
@tomchristie I don't use routers/viewsets but using generics .. when you go to /category/subcategory you get a list of subcategory I don't want to use /subcategory directly and it seems wrong to me to don't support subcategories on APIs is common than I thought, so maybe we should move this issue directly to DRF then. |
Do that yup. It'll likely be a case of us providing explicit ways to get the layout you want when the default case isn't quite right, but either way we'll need to make that possible/easier. |
I have
PhotosViewSet
with list andlist_route
upload action.I would like it to see under same 'photos' group in the docs.
What i am doing wrong? Is it supported?
in
SchemaGenerator
get_key
seems to not take 'list route' actions into account.The text was updated successfully, but these errors were encountered: