-
Notifications
You must be signed in to change notification settings - Fork 252
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 setting to disable nested path pk coercion. #516
Conversation
Codecov Report
@@ Coverage Diff @@
## master #516 +/- ##
==========================================
- Coverage 98.63% 98.63% -0.01%
==========================================
Files 58 58
Lines 5944 5987 +43
==========================================
+ Hits 5863 5905 +42
- Misses 81 82 +1
Continue to review full report at Codecov.
|
dc64ed7
to
71ee65e
Compare
71ee65e
to
6dc3a62
Compare
For me, this is the deal breaker i did not properly think about. Having a mixture of |
improved support for drf-nested-routers
hey @ngnpope, gave this more thought and came to the conlusion it should be disabled by default. i had to fix up a couple of places to make detection robust enough. i think this should now cover almost all cases.
thank you for the PR and getting me started here. could you try out if the current master works for you? |
Hey @tfranzel, I've given this a go and I get fewer warnings than I had before, so if that is a measure of success then great! 😆 |
i would say so. i actually think of the warnings as a todo list of schema problems. after all, most warning are there to guide you to a better schema. |
This is another thing I came across in my conversions from
drf-yasg
which doesn't have any support for converting path parameters for nested routers, but does handle{pk}
to{id}
based onSCHEMA_COERCE_PATH_PK
.I wanted to disable this behaviour in
drf-spectacular
for the following reasons:drf-yasg
converted to OpenAPI 3.0 (with a bunch of other clean-ups) against the OpenAPI 3.0 schema produced bydrf-spectacular
.django-treebeard
and the tree-like structures have no self-referencing foreign key to follow, e.g. for a tree of folders,{parent_pk}
won't be changed to{parent_id}
./{company_pk}/person/{pk}
where the relationship isPerson
→Department
→Company
. In this casePerson.company
doesn't exist and there is some custom querying to look up the value.Where this becomes a mess is when we have something like
/x/{a_pk}/y/{b_pk}/z/{pk}
that becomes/x/{a_id}/y/{b_pk}/z/{id}
which is inconsistent.I had thought that it would be nice to have something that allows us to forcibly override this for certain models, e.g. we could pretend that
Person.company
existed. Obviously we'd then need to override the type using@extend_schema(parameters=...)
That would looks something like:Would something like that also be acceptable?
It seems a shame that, when we set
SCHEMA_COERCE_PATH_PK_NESTED
toFalse
, we're forced to manually specify the parameters as though it forgets that{user_pk}
is still the equivalent to{user_id}
Maybe I'm missing something...