-
Notifications
You must be signed in to change notification settings - Fork 273
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
Add test when simple view is interpreted as list view #20
Conversation
Thing is, spectacular uses 'is_list_view' to determine whether view is listing or not. If it is then response is wrapped in array and operation ID has suffix '_list'. 'is_list_view' has some heuristics, and the last of them is to explode route and check if the last part is dynamic parameter like {id}. So, if you have APIView with route that doesn't end with such parameter, you will end up with response serializer wrapped with array just because of the failed heuristic!
2ca6ced
to
f499dc4
Compare
Diff of generated schema with reference file is the following:
|
yes indeed that is a bug from the old code. i knew that was gonna pop up eventually. i already marked the spot with a todo that this is probably not gonna cover all cases. so now we have it. i'll have a look and refactor that broken heuristic. |
Now I have stopped switching the schema to the 3.0 due to this problem :-( I learned a little how the drf_yasg handles this situation. |
hi @MissiaL, thanks for the info. i had a look at yasg and they are also using a heuristic in the end: https://github.com/axnsan12/drf-yasg/blob/9ccf24c27ad46db4f566170553d49d687b6d21d6/src/drf_yasg/utils.py#L211 but apparently a slightly better one. however, this heuristic also breaks down occasionally. we have seen that in our own usage of yasg. i'm actively on it and almost have a "as good as it gets" solution. by tomorrow i will have something to look at. |
sry for the delay but i couldn't find the time earlier. so i tried something different here. this is really one of the more tricky parts.
default for the new @tsouvarev i refactored the test into 2 separate test that explicitly only check this as the other test was already quite large. @MissiaL let me know if that works for you now. |
It works perfect! Thanks! |
Spectacular uses
is_list_view
to determine whether view is listing or not. If it is then response is wrapped in array and operation ID has suffix_list
.is_list_view
has some heuristics, and the last of them is to explode route and check if the last part is dynamic parameter like{id}
.So, if you have APIView with route that doesn't end with such parameter, you will end up with response serializer wrapped with array just because of the failed heuristic.