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.38k stars 264 forks source link

Lookup field detected as int in nested router #678

Closed mounirmesselmeni closed 2 years ago

mounirmesselmeni commented 2 years ago

(Not an int ID)

but what is it then? are there warning emitted to the console? spectacular should default to str if nothing can be resolved. so i'm assuming some field (of type integer) got found there. we would need a reproduction to further investigate.

The lookup regex is the following: (?P[^/.]+)

that is the default regex for all of DRF's path parameters. if spectacular sees that, it tries to be smarter and find a field type for that name custom_id.

for further discussion please open a new issue.

Originally posted by @tfranzel in https://github.com/tfranzel/drf-spectacular/issues/453#issuecomment-1063351328

The field is of type string and named api_id. It's basically a UUID with a string prefix.

The weird behavior for me is that Im getting this problen only for nested viewsets, for the other ones it's in fact defaulting to string (using the same field name but on a different model)

There are also no warnings during schema generation with drf spectacular

tfranzel commented 2 years ago

On first sight the resolution mechanics look ok. We do have a couple of tests that cover rest_framework_nested: https://github.com/tfranzel/drf-spectacular/blob/master/tests/contrib/test_drf_nested_routers.py

could you try and build a minimal reproduction? otherwise it will be very hard resolving this.

tfranzel commented 2 years ago

closing this stale issue for now. feel free to comment if anything is missing or not working and we will follow-up.