From 6e1ddb671e8b50a40a230aa63808285af39c876e Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Sun, 20 Aug 2023 20:18:22 +1000 Subject: [PATCH] feat(nodes): make fields that accept connection input optional in OpenAPI schema Doing this via `BaseInvocation`'s `Config.schema_extra()` means all clients get an accurate OpenAPI schema. Shifts the responsibility of correct types to the backend, where previously it was on the client. --- invokeai/app/invocations/baseinvocation.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/invokeai/app/invocations/baseinvocation.py b/invokeai/app/invocations/baseinvocation.py index d9bdcc988b..99f48122cf 100644 --- a/invokeai/app/invocations/baseinvocation.py +++ b/invokeai/app/invocations/baseinvocation.py @@ -464,6 +464,16 @@ class BaseInvocation(ABC, BaseModel): schema["required"] = list() schema["required"].extend(["type", "id"]) + # nodes may have required fields, that can accept input from connections + # mark them as optional in the schema + for field_name, field in model_class.__fields__.items(): + _input = field.field_info.extra.get("input", None) + if _input in [Input.Connection, Input.Any]: + try: + schema["required"].remove(field_name) + except Exception: + pass + @abstractmethod def invoke(self, context: InvocationContext) -> BaseInvocationOutput: """Invoke with provided context and return outputs."""