tfranzel / drf-spectacular

Sane and flexible OpenAPI 3 schema generation for Django REST framework.
https://drf-spectacular.readthedocs.io
BSD 3-Clause "New" or "Revised" License
2.41k stars 266 forks source link

Warning with 3 levels of nested router #731

Open mdefeche opened 2 years ago

mdefeche commented 2 years ago

I saw fixes #453 & #456 which allowed me to get rid of several warnings.

I still have one when I use drf-nested-router with 3 levels. For instance I have survey/survey_id/response/response_id/answer/

Warning #0: AnswerViewSet: could not derive type of path parameter "survey_id" because model "questionnaire.models.Answer" contained no such field. Consider annotating parameter with @extend_schema. Defaulting to "string".

I could fix it with @extend_schema or @extend_schema_view, but it looks more like a workaround now that other cases are properly handled.

@extend_schema_view(
    list=extend_schema(tags=["answer"], parameters=[OpenApiParameter(name="survey_id", type=OpenApiTypes.INT, location=OpenApiParameter.PATH)]),
    retrieve=extend_schema(tags=["answer"], parameters=[OpenApiParameter(name="survey_id", type=OpenApiTypes.INT, location=OpenApiParameter.PATH)]),
    create=extend_schema(tags=["answer"], parameters=[OpenApiParameter(name="survey_id", type=OpenApiTypes.INT, location=OpenApiParameter.PATH)]),
)

Version = 0.22.1

Very much appreciate all the efforts put into this library

tfranzel commented 2 years ago

Hi @mdefeche

I tested the https://github.com/alanjds/drf-nested-routers#infinite-depth-nesting example and it looks ok to me. We don't have special handling for 2 levels and so 3 levels shouldn't be any different from our point of view.

please have a look at https://github.com/tfranzel/drf-spectacular/blob/master/tests/contrib/test_drf_nested_routers.py It would really help if you could reproduce the issue (ideally based on the existing tests).