Skip to content
Discussion options

You must be logged in to vote

You haven't done anything wrong. depth and drf-spectacular just don't work well together out of the box. For every relation, DRF builds the nested serializer on the fly as a local class that is always named NestedSerializer (build_nested_field). drf-spectacular derives the component name from the class name, so every relation becomes a component called Nested. The warning is real: I reproduced it with two FKs and depth = 1, and both fields ended up pointing at the same #/components/schemas/Nested, so one of them is documented with the wrong model.

DRF won't rename these by default, but you can give them unique names in your base serializer. Cache one class per related model so drf-spectac…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by antonkozel-az
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants