chore: mypy for strong_typing

Mostly just ignores because of the dynamic nature of the codebase. One
prominent change is expanding the allowed types for attributes tracking
property types to allow strings (which are valid and common typing hints
in python).

Signed-off-by: Ihar Hrachyshka <ihar.hrachyshka@gmail.com>
This commit is contained in:
Ihar Hrachyshka 2025-03-20 17:12:58 -04:00
parent ba14552a32
commit d5b52923c1
7 changed files with 15 additions and 17 deletions

View file

@ -460,13 +460,13 @@ class JsonSchemaGenerator:
discriminator = None
if typing.get_origin(data_type) is Annotated:
discriminator = typing.get_args(data_type)[1].discriminator
ret = {"oneOf": [self.type_to_schema(union_type) for union_type in typing.get_args(typ)]}
ret: Schema = {"oneOf": [self.type_to_schema(union_type) for union_type in typing.get_args(typ)]}
if discriminator:
# for each union type, we need to read the value of the discriminator
mapping = {}
mapping: JsonType = {}
for union_type in typing.get_args(typ):
props = self.type_to_schema(union_type, force_expand=True)["properties"]
mapping[props[discriminator]["default"]] = self.type_to_schema(union_type)["$ref"]
mapping[props[discriminator]["default"]] = self.type_to_schema(union_type)["$ref"] # type: ignore
ret["discriminator"] = {
"propertyName": discriminator,