mirror of
https://github.com/nix-community/disko.git
synced 2026-11-30 21:13:28 +01:00
disko2: Validate config for type-safety in python
This commit is contained in:
1 parent
ae7891e21f
commit
6651792c28
15 files changed
+299
-83
No files matched your search
@@ -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
|
||||
|
||||
|
||||
"""
|
||||
|
||||
Reference in new issue
Block a user