No longer need to specify entity_type in body
This commit is contained in:
@@ -59,7 +59,7 @@ async def update(
|
||||
key: Annotated[str, Path(min_length=1, max_length=64, regex="^[a-z0-9_]+$")],
|
||||
body: ExtraFieldParameters,
|
||||
) -> Union[list[ExtraField], JSONResponse]:
|
||||
body_with_key = ExtraField.parse_obj(body.copy(update={"key": key}))
|
||||
body_with_key = ExtraField.parse_obj(body.copy(update={"key": key, "entity_type": entity_type}))
|
||||
|
||||
try:
|
||||
await add_or_update_extra_field(db, entity_type, body_with_key)
|
||||
|
||||
@@ -36,7 +36,6 @@ class ExtraFieldType(Enum):
|
||||
class ExtraFieldParameters(BaseModel):
|
||||
name: str = Field(description="Nice name", min_length=1, max_length=128)
|
||||
unit: Optional[str] = Field(None, description="Unit of the value", min_length=1, max_length=16)
|
||||
entity_type: EntityType = Field(description="Entity type this field is for")
|
||||
field_type: ExtraFieldType = Field(description="Type of the field")
|
||||
default_value: Optional[str] = Field(None, description="Default value of the field")
|
||||
choices: Optional[list[str]] = Field(None, description="Choices for the field, only for field type choice")
|
||||
@@ -45,6 +44,7 @@ class ExtraFieldParameters(BaseModel):
|
||||
|
||||
class ExtraField(ExtraFieldParameters):
|
||||
key: str = Field(description="Unique key", regex="^[a-z0-9_]+$", min_length=1, max_length=64)
|
||||
entity_type: EntityType = Field(description="Entity type this field is for")
|
||||
|
||||
|
||||
def validate_extra_field_value(field: ExtraFieldParameters, value: str) -> None: # noqa: C901, PLR0912
|
||||
|
||||
Reference in New Issue
Block a user