Closed sommelon closed 3 years ago
hi @sommelon, most warning don't have an impact on the schema. they are just supposed to signal that something is fishy.
we do not support django-restql
at this moment. nobody tells you not to use drf-spectacular
, but ther are no guarantees and your mileage may vary. the highly dynamic nature may prove tricky to properly map. it may be possible to get quite far with writing OpenApiSerializerFieldExtension and OpenApiSerializerExtension. we did something similar with django-polymorphic
. currently i don't have the time to implement this (or even try to). feel free to upstream this though, if you attempt to do it.
The problem I have with the warnings is that it's hard to see if something new is being reported (errors or a different kind of warning).
I will try to fix it using an extension, thanks.
I tried SerializerField and Serializer extensions, but couldn't get them to work.
Instead I overrode _get_serializer_name()
in my custom schema. Not the best solution, but it will do it for me.
def _get_serializer_name(self, serializer, direction):
name = super()._get_serializer_name(serializer, direction)
if serializer.__class__.__name__ == 'NestedSerializer':
name += 'Nested' + str(randint(1,99999))
return name
It's generating new components with different names every time, so I will use it only when I want to check for new warnings.
I ended up monkey-patching the drf_spectacular.plumbing.warn
name in the projects __init__.py
.
import drf_spectacular.plumbing
import drf_spectacular.drainage
def __suppressed_warn(msg):
if 'components with identical' in msg and '<locals>.Nested' in msg:
return
drf_spectacular.drainage.warn(msg)
drf_spectacular.plumbing.warn = __suppressed_warn
Hello, I mentioned previously that I'm using django-restql for nested serializers. I have to define my serializers like this
The problem is, that the schema gets generated incorrectly. It repeats the same nested serializer for every
NestedField
there is.In the example above, my
AddressSerializer
is replacing theContactInfoSerializer
andBusinessDetailSerializer
. I think it's because theAddressSerializer
is used in my first view in the project. To fix this, I addedref_name
to each serializer. It works, but I get a lot of warnings.Their implementation uses a wrapper that returns a serializer.
Is there a way I can get rid of the warnings and, possibly, the need to define
ref_name
on every serializer?