disko2: Validate config for type-safety in python

This commit is contained in:
Felix Uhl committed 2024-11-17 21:37:39 +01:00
1 parent ae7891e21f
commit 6651792c28
15 files changed
+299 -83

No files matched your search

+6 -1
View File
@@ -112,6 +112,11 @@ def _parse_simple_type(type_str: str) -> str:
return "int"
case "anything":
return "Any"
# Set up discriminated unions to reduce error messages when validation fails
case "deviceType":
return '"deviceType" = Field(..., discriminator="type")'
case "partitionType":
return '"partitionType" = Field(..., discriminator="type")'
case _:
# Probably a type alias, needs to be quoted in case the type is defined later
return f'"{type_str}"'
@@ -212,7 +217,7 @@ def generate_python_code(schema: JsonDict) -> io.StringIO:
# Disable auto-formatting for this file
# fmt: off
from typing import Any, Literal, Union
from pydantic import BaseModel
from pydantic import BaseModel, Field
"""