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.
This commit is contained in:
psychedelicious 2023-08-20 20:18:22 +10:00
parent 496a2db15c
commit 6e1ddb671e

View File

@ -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."""