feat(nodes): make id, type required in BaseInvocation, BaseInvocationOutput

Doing this via these classes' `Config.schema_extra()` method makes it unintrusive and clients will get the correct types for these properties.

Shifts the responsibility of correct types to the backend, where previously it was on the client.
This commit is contained in:
psychedelicious 2023-08-20 20:02:41 +10:00
parent 5292eda0e4
commit 496a2db15c

View File

@ -393,6 +393,13 @@ class BaseInvocationOutput(BaseModel):
toprocess.extend(next_subclasses)
return tuple(subclasses)
class Config:
@staticmethod
def schema_extra(schema: dict[str, Any], model_class: Type[BaseModel]) -> None:
if "required" not in schema or not isinstance(schema["required"], list):
schema["required"] = list()
schema["required"].extend(["type"])
class RequiredConnectionException(Exception):
"""Raised when an field which requires a connection did not receive a value."""
@ -453,6 +460,9 @@ class BaseInvocation(ABC, BaseModel):
schema["title"] = uiconfig.title
if uiconfig and hasattr(uiconfig, "tags"):
schema["tags"] = uiconfig.tags
if "required" not in schema or not isinstance(schema["required"], list):
schema["required"] = list()
schema["required"].extend(["type", "id"])
@abstractmethod
def invoke(self, context: InvocationContext) -> BaseInvocationOutput: