Add additionalProperties
to keys that do not discard the resolved serializer
#299
Labels
bug
Something isn't working
fix confirmation pending
issue has been fixed and confirmation from issue reporter is pending
Mostly creating this as a self-reminder for a PR to create, but, the following code:
drf-spectacular/drf_spectacular/openapi.py
Line 1073 in f219b6e
triggers whether a resolved serializer component is kept in the schema or not. The logic has some support for the typical polymorphic properties (
oneOf
,anyOf
,allOf
) and also explicit schemas - i.e. theproperties
key is set and the schema actually has a pre-defined shape.However, we're in a highly dynamic use case, see our polymorphism implementation.
additionalProperties: true
is typically used in OpenAPIresolve_serializer
discards it. Because it's discarded, the empty string discriminator value is discarded as well, so the whole dynamic form serializer doesn't show up in the schema.I've solved this by generating a
ResolvedComponent
in the polymorphic serializer extension, however this is a pattern that will be used outside of polymorphic serializers as well.The clean solution would be to have a base serializer, e.g.
class HashMapSerializer(serializers.Serializer): pass
, and all the dynamic run-time behaviour can be in subclasses (in the__new__
class method for example). Then, we can write anOpenApiSerializerExtension
targeting that class, which generates an object_type:resolve_serializer
then also needs to keep the schema ifadditionalProperties
is found in the schema, and everyone is happy :-)The text was updated successfully, but these errors were encountered: