drf-spectacular
drf-spectacular copied to clipboard
Ability to access the direction and auto_schema in MarshmallowSerializerExtension.get_name method
is it possible to get the direction
and auto_schema
(or at least the ViewSet class) in MarshmallowSerializerExtension get_name
methods?
I need the direction and some properties from ViewSet class to generate the name correctly. (and in some cases to solve the naming conflict issue)
the fix should be easy. problem is that this breaks everybody using get_name
in an extension. i failed to include a **kwargs
in the beginning so that its forward compatible. i'm undecided whether the reward outweighs the risk here.
the SerializerFieldExtension.get_name
is rather special but SerializerExtension.get_name
might hit more users.
@tfranzel thank you!
for now, as a workaround, I implemented a custom AutoSchema
class with a custom implementation of _get_serializer_name
and _get_response_for_code
methods to inject/pass the data I need
awesome! i'll leave this open to gather some support from other users. if this becomes a more common pain point we can look at it again.
in the meantime i should add kwargs
to future-proof this for new user from here on out.
so I just hit this problem without a proper way to achieve the goal. Direction
was indeed needed. I found a way to safely call legacy get_name
without the new arguments. Also added auto_schema
, as this might be helpful and I don't want to change it again, i.e. breaking people twice. This should be rather safe but you never know.
Even got a new feature on top of that. When this is merged, your custom AutoSchema
might break. Just as a heads-up
Cool!
I liked how you did the backward compatibility (by Checking the method signature), and I think the changes are safe (the changes should only affect the users with custom AutoSchema
implemented - as I did -).
I think I can easily update my implementation to use the new signature of the get_name
method.
Thank you!