]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
utils: modelling: json_schema serializer modified to allow derived 'CustomValueType'
authorAleš <ales.mrazek@nic.cz>
Fri, 26 Nov 2021 16:53:36 +0000 (17:53 +0100)
committerAleš Mrázek <ales.mrazek@nic.cz>
Fri, 8 Apr 2022 14:17:53 +0000 (16:17 +0200)
manager/knot_resolver_manager/utils/modelling.py

index b368a047ca4ab697183ba9effba65944e7b436a4..ddc5adb1eee2ad4d300ee914130d66d89ef4cd5c 100644 (file)
@@ -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):