From: Aleš Date: Fri, 26 Nov 2021 16:53:36 +0000 (+0100) Subject: utils: modelling: json_schema serializer modified to allow derived 'CustomValueType' X-Git-Tag: v6.0.0a1~69^2~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b73271029f863316c7ddfdff5a7ec5be9a721dec;p=thirdparty%2Fknot-resolver.git utils: modelling: json_schema serializer modified to allow derived 'CustomValueType' --- diff --git a/manager/knot_resolver_manager/utils/modelling.py b/manager/knot_resolver_manager/utils/modelling.py index b368a047c..ddc5adb1e 100644 --- a/manager/knot_resolver_manager/utils/modelling.py +++ b/manager/knot_resolver_manager/utils/modelling.py @@ -175,7 +175,14 @@ def _describe_type(typ: Type[Any]) -> Dict[Any, Any]: elif is_dict(typ): key, val = get_generic_type_arguments(typ) - assert key == str, "We currently do not support any other keys then strings" + + if inspect.isclass(key) and issubclass(key, CustomValueType): + assert ( + key.__str__ is not CustomValueType.__str__ + ), "To support derived 'CustomValueType', __str__ must be implemented." + else: + assert key == str, "We currently do not support any other keys then strings" + return {"type": "object", "additionalProperties": _describe_type(val)} elif is_enum(typ):