feat(ui): add typegen customisation for invocation outputs

The `type` property is required on all of them, but because this is defined in pydantic as a Literal, it is not required in the OpenAPI schema. Easier to fix this by changing the generated types than fiddling around with pydantic.
This commit is contained in:
psychedelicious 2023-08-18 20:19:36 +10:00
parent 484b572023
commit f952f8f685
2 changed files with 74 additions and 61 deletions

View File

@ -42,7 +42,6 @@ async function main() {
// We only want to make fields optional if they are required // We only want to make fields optional if they are required
if (!Array.isArray(schemaObject?.required)) { if (!Array.isArray(schemaObject?.required)) {
schemaObject.required = ['id', 'type']; schemaObject.required = ['id', 'type'];
return;
} }
schemaObject.required.forEach((prop) => { schemaObject.required.forEach((prop) => {
@ -68,12 +67,26 @@ async function main() {
return; return;
} }
// if (
// 'input' in schemaObject && // Check if we are generating types for an invocation output
// (schemaObject.input === 'any' || schemaObject.input === 'connection') const isInvocationOutputPath = metadata.path.match(
// ) { /^#\/components\/schemas\/\w*Output$/
// schemaObject.required = false; );
// }
const hasOutputProperties =
schemaObject.properties && 'type' in schemaObject.properties;
if (isInvocationOutputPath && hasOutputProperties) {
if (!Array.isArray(schemaObject?.required)) {
schemaObject.required = ['type'];
}
schemaObject.required = [
...new Set(schemaObject.required.concat(['type'])),
];
console.log(
`Making output's "type" required: ${COLORS.fg.yellow}${schemaObject.title}${COLORS.reset}`
);
}
}, },
}); });
fs.writeFileSync(OUTPUT_FILE, types); fs.writeFileSync(OUTPUT_FILE, types);

View File

@ -611,7 +611,7 @@ export type components = {
* @default boolean_collection_output * @default boolean_collection_output
* @enum {string} * @enum {string}
*/ */
type?: "boolean_collection_output"; type: "boolean_collection_output";
/** /**
* Collection * Collection
* @description The output boolean collection * @description The output boolean collection
@ -641,11 +641,11 @@ export type components = {
*/ */
type: "boolean"; type: "boolean";
/** /**
* A * Value
* @description The boolean value * @description The boolean value
* @default false * @default false
*/ */
a?: boolean; value?: boolean;
}; };
/** /**
* BooleanOutput * BooleanOutput
@ -657,12 +657,12 @@ export type components = {
* @default boolean_output * @default boolean_output
* @enum {string} * @enum {string}
*/ */
type?: "boolean_output"; type: "boolean_output";
/** /**
* A * Value
* @description The output boolean * @description The output boolean
*/ */
a: boolean; value: boolean;
}; };
/** /**
* Canny Processor * Canny Processor
@ -771,7 +771,7 @@ export type components = {
* @default clip_skip_output * @default clip_skip_output
* @enum {string} * @enum {string}
*/ */
type?: "clip_skip_output"; type: "clip_skip_output";
/** /**
* CLIP * CLIP
* @description CLIP (tokenizer, text encoder, LoRAs) and skipped layer count * @description CLIP (tokenizer, text encoder, LoRAs) and skipped layer count
@ -821,7 +821,7 @@ export type components = {
* @default collect_output * @default collect_output
* @enum {string} * @enum {string}
*/ */
type?: "collect_output"; type: "collect_output";
/** /**
* Collection * Collection
* @description The collection of input items * @description The collection of input items
@ -838,7 +838,7 @@ export type components = {
* @default color_collection_output * @default color_collection_output
* @enum {string} * @enum {string}
*/ */
type?: "color_collection_output"; type: "color_collection_output";
/** /**
* Collection * Collection
* @description The output colors * @description The output colors
@ -960,7 +960,7 @@ export type components = {
* @default color_output * @default color_output
* @enum {string} * @enum {string}
*/ */
type?: "color_output"; type: "color_output";
/** /**
* Color * Color
* @description The output color * @description The output color
@ -1040,7 +1040,7 @@ export type components = {
* @default conditioning_collection_output * @default conditioning_collection_output
* @enum {string} * @enum {string}
*/ */
type?: "conditioning_collection_output"; type: "conditioning_collection_output";
/** /**
* Collection * Collection
* @description The output conditioning tensors * @description The output conditioning tensors
@ -1096,7 +1096,7 @@ export type components = {
* @default conditioning_output * @default conditioning_output
* @enum {string} * @enum {string}
*/ */
type?: "conditioning_output"; type: "conditioning_output";
/** /**
* Conditioning * Conditioning
* @description Conditioning tensor * @description Conditioning tensor
@ -1339,7 +1339,7 @@ export type components = {
* @default control_output * @default control_output
* @enum {string} * @enum {string}
*/ */
type?: "control_output"; type: "control_output";
/** /**
* Control * Control
* @description ControlNet(s) to apply * @description ControlNet(s) to apply
@ -1578,7 +1578,7 @@ export type components = {
*/ */
steps?: number; steps?: number;
/** /**
* Cfg Scale * CFG Scale
* @description Classifier-Free Guidance scale * @description Classifier-Free Guidance scale
* @default 7.5 * @default 7.5
*/ */
@ -1628,7 +1628,7 @@ export type components = {
*/ */
negative_conditioning?: components["schemas"]["ConditioningField"]; negative_conditioning?: components["schemas"]["ConditioningField"];
/** /**
* Unet * UNet
* @description UNet (scheduler, LoRAs) * @description UNet (scheduler, LoRAs)
*/ */
unet?: components["schemas"]["UNetField"]; unet?: components["schemas"]["UNetField"];
@ -1808,7 +1808,7 @@ export type components = {
* @default float_collection_output * @default float_collection_output
* @enum {string} * @enum {string}
*/ */
type?: "float_collection_output"; type: "float_collection_output";
/** /**
* Collection * Collection
* @description The float collection * @description The float collection
@ -1838,11 +1838,11 @@ export type components = {
*/ */
type: "float"; type: "float";
/** /**
* Param * Value
* @description The float value * @description The float value
* @default 0 * @default 0
*/ */
param?: number; value?: number;
}; };
/** /**
* Float Range * Float Range
@ -1895,12 +1895,12 @@ export type components = {
* @default float_output * @default float_output
* @enum {string} * @enum {string}
*/ */
type?: "float_output"; type: "float_output";
/** /**
* A * Value
* @description The output float * @description The output float
*/ */
a: number; value: number;
}; };
/** Graph */ /** Graph */
Graph: { Graph: {
@ -2199,7 +2199,7 @@ export type components = {
* @default image_collection_output * @default image_collection_output
* @enum {string} * @enum {string}
*/ */
type?: "image_collection_output"; type: "image_collection_output";
/** /**
* Collection * Collection
* @description The output images * @description The output images
@ -2647,7 +2647,7 @@ export type components = {
* @default image_output * @default image_output
* @enum {string} * @enum {string}
*/ */
type?: "image_output"; type: "image_output";
/** /**
* Image * Image
* @description The output image * @description The output image
@ -3151,7 +3151,7 @@ export type components = {
* @default integer_collection_output * @default integer_collection_output
* @enum {string} * @enum {string}
*/ */
type?: "integer_collection_output"; type: "integer_collection_output";
/** /**
* Collection * Collection
* @description The int collection * @description The int collection
@ -3181,11 +3181,11 @@ export type components = {
*/ */
type: "integer"; type: "integer";
/** /**
* A * Value
* @description The integer value * @description The integer value
* @default 0 * @default 0
*/ */
a?: number; value?: number;
}; };
/** /**
* IntegerOutput * IntegerOutput
@ -3197,12 +3197,12 @@ export type components = {
* @default integer_output * @default integer_output
* @enum {string} * @enum {string}
*/ */
type?: "integer_output"; type: "integer_output";
/** /**
* A * Value
* @description The output integer * @description The output integer
*/ */
a: number; value: number;
}; };
/** /**
* IterateInvocation * IterateInvocation
@ -3248,7 +3248,7 @@ export type components = {
* @default iterate_output * @default iterate_output
* @enum {string} * @enum {string}
*/ */
type?: "iterate_output"; type: "iterate_output";
/** /**
* Collection Item * Collection Item
* @description The item being iterated over * @description The item being iterated over
@ -3294,7 +3294,7 @@ export type components = {
* @default latents_collection_output * @default latents_collection_output
* @enum {string} * @enum {string}
*/ */
type?: "latents_collection_output"; type: "latents_collection_output";
/** /**
* Collection * Collection
* @description Latents tensor * @description Latents tensor
@ -3355,7 +3355,7 @@ export type components = {
* @default latents_output * @default latents_output
* @enum {string} * @enum {string}
*/ */
type?: "latents_output"; type: "latents_output";
/** /**
* Latents * Latents
* @description Latents tensor * @description Latents tensor
@ -3697,7 +3697,7 @@ export type components = {
* @default lora_loader_output * @default lora_loader_output
* @enum {string} * @enum {string}
*/ */
type?: "lora_loader_output"; type: "lora_loader_output";
/** /**
* UNet * UNet
* @description UNet (scheduler, LoRAs) * @description UNet (scheduler, LoRAs)
@ -4076,7 +4076,7 @@ export type components = {
* @default metadata_accumulator_output * @default metadata_accumulator_output
* @enum {string} * @enum {string}
*/ */
type?: "metadata_accumulator_output"; type: "metadata_accumulator_output";
/** /**
* Metadata * Metadata
* @description The core metadata for the image * @description The core metadata for the image
@ -4205,7 +4205,7 @@ export type components = {
* @default model_loader_output * @default model_loader_output
* @enum {string} * @enum {string}
*/ */
type?: "model_loader_output"; type: "model_loader_output";
/** /**
* UNet * UNet
* @description UNet (scheduler, LoRAs) * @description UNet (scheduler, LoRAs)
@ -4330,7 +4330,7 @@ export type components = {
* @default noise_output * @default noise_output
* @enum {string} * @enum {string}
*/ */
type?: "noise_output"; type: "noise_output";
/** /**
* Noise * Noise
* @description Noise tensor * @description Noise tensor
@ -4435,7 +4435,7 @@ export type components = {
* @default model_loader_output_onnx * @default model_loader_output_onnx
* @enum {string} * @enum {string}
*/ */
type?: "model_loader_output_onnx"; type: "model_loader_output_onnx";
/** /**
* UNet * UNet
* @description UNet (scheduler, LoRAs) * @description UNet (scheduler, LoRAs)
@ -5253,7 +5253,7 @@ export type components = {
* @default sdxl_lora_loader_output * @default sdxl_lora_loader_output
* @enum {string} * @enum {string}
*/ */
type?: "sdxl_lora_loader_output"; type: "sdxl_lora_loader_output";
/** /**
* UNet * UNet
* @description UNet (scheduler, LoRAs) * @description UNet (scheduler, LoRAs)
@ -5308,7 +5308,7 @@ export type components = {
* @default sdxl_model_loader_output * @default sdxl_model_loader_output
* @enum {string} * @enum {string}
*/ */
type?: "sdxl_model_loader_output"; type: "sdxl_model_loader_output";
/** /**
* UNet * UNet
* @description UNet (scheduler, LoRAs) * @description UNet (scheduler, LoRAs)
@ -5428,7 +5428,7 @@ export type components = {
* @default sdxl_refiner_model_loader_output * @default sdxl_refiner_model_loader_output
* @enum {string} * @enum {string}
*/ */
type?: "sdxl_refiner_model_loader_output"; type: "sdxl_refiner_model_loader_output";
/** /**
* UNet * UNet
* @description UNet (scheduler, LoRAs) * @description UNet (scheduler, LoRAs)
@ -5824,7 +5824,7 @@ export type components = {
* @default string_collection_output * @default string_collection_output
* @enum {string} * @enum {string}
*/ */
type?: "string_collection_output"; type: "string_collection_output";
/** /**
* Collection * Collection
* @description The output strings * @description The output strings
@ -5854,11 +5854,11 @@ export type components = {
*/ */
type: "string"; type: "string";
/** /**
* Text * Value
* @description The string value * @description The string value
* @default * @default
*/ */
text?: string; value?: string;
}; };
/** /**
* StringOutput * StringOutput
@ -5870,12 +5870,12 @@ export type components = {
* @default string_output * @default string_output
* @enum {string} * @enum {string}
*/ */
type?: "string_output"; type: "string_output";
/** /**
* Text * Value
* @description The output string * @description The output string
*/ */
text: string; value: string;
}; };
/** /**
* SubModelType * SubModelType
@ -6060,7 +6060,7 @@ export type components = {
* @default vae_loader_output * @default vae_loader_output
* @enum {string} * @enum {string}
*/ */
type?: "vae_loader_output"; type: "vae_loader_output";
/** /**
* VAE * VAE
* @description VAE * @description VAE
@ -6160,7 +6160,7 @@ export type components = {
* If a field should be provided a data type that does not exactly match the python type of the field, use this to provide the type that should be used instead. See the node development docs for detail on adding a new field type, which involves client-side changes. * If a field should be provided a data type that does not exactly match the python type of the field, use this to provide the type that should be used instead. See the node development docs for detail on adding a new field type, which involves client-side changes.
* @enum {string} * @enum {string}
*/ */
UIType: "integer" | "float" | "boolean" | "string" | "array" | "ImageField" | "LatentsField" | "ConditioningField" | "ControlField" | "ColorField" | "ImageCollection" | "ConditioningCollection" | "ColorCollection" | "LatentsCollection" | "IntegerCollection" | "FloatCollection" | "StringCollection" | "BooleanCollection" | "MainModelField" | "SDXLMainModelField" | "SDXLRefinerModelField" | "ONNXModelField" | "VaeModelField" | "LoRAModelField" | "ControlNetModelField" | "UNetField" | "VaeField" | "ClipField" | "Collection" | "CollectionItem" | "FilePath" | "enum"; UIType: "integer" | "float" | "boolean" | "string" | "array" | "ImageField" | "LatentsField" | "ConditioningField" | "ControlField" | "ColorField" | "ImageCollection" | "ConditioningCollection" | "ColorCollection" | "LatentsCollection" | "IntegerCollection" | "FloatCollection" | "StringCollection" | "BooleanCollection" | "MainModelField" | "SDXLMainModelField" | "SDXLRefinerModelField" | "ONNXModelField" | "VaeModelField" | "LoRAModelField" | "ControlNetModelField" | "UNetField" | "VaeField" | "ClipField" | "Collection" | "CollectionItem" | "FilePath" | "enum" | "Scheduler";
/** /**
* UIComponent * UIComponent
* @description The type of UI component to use for a field, used to override the default components, which are inferred from the field type. * @description The type of UI component to use for a field, used to override the default components, which are inferred from the field type.
@ -6211,18 +6211,18 @@ export type components = {
* @enum {string} * @enum {string}
*/ */
ControlNetModelFormat: "checkpoint" | "diffusers"; ControlNetModelFormat: "checkpoint" | "diffusers";
/**
* StableDiffusion2ModelFormat
* @description An enumeration.
* @enum {string}
*/
StableDiffusion2ModelFormat: "checkpoint" | "diffusers";
/** /**
* StableDiffusionXLModelFormat * StableDiffusionXLModelFormat
* @description An enumeration. * @description An enumeration.
* @enum {string} * @enum {string}
*/ */
StableDiffusionXLModelFormat: "checkpoint" | "diffusers"; StableDiffusionXLModelFormat: "checkpoint" | "diffusers";
/**
* StableDiffusion2ModelFormat
* @description An enumeration.
* @enum {string}
*/
StableDiffusion2ModelFormat: "checkpoint" | "diffusers";
}; };
responses: never; responses: never;
parameters: never; parameters: never;