mirror of
https://github.com/invoke-ai/InvokeAI
synced 2024-08-30 20:32:17 +00:00
fix(ui): simplify typegen script
i had this committed earlier but lost it somehow
This commit is contained in:
parent
b79bca2c14
commit
35d14fc0f9
@ -27,21 +27,10 @@ async function main() {
|
|||||||
* field accepts connection input. If it does, we can make the field optional.
|
* field accepts connection input. If it does, we can make the field optional.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Check if we are generating types for an invocation
|
if ('class' in schemaObject && schemaObject.class === 'invocation') {
|
||||||
const isInvocationPath = metadata.path.match(
|
|
||||||
/^#\/components\/schemas\/\w*Invocation$/
|
|
||||||
);
|
|
||||||
|
|
||||||
const hasInvocationProperties =
|
|
||||||
schemaObject.properties &&
|
|
||||||
['id', 'is_intermediate', 'type'].every(
|
|
||||||
(prop) => prop in schemaObject.properties
|
|
||||||
);
|
|
||||||
|
|
||||||
if (isInvocationPath && hasInvocationProperties) {
|
|
||||||
// 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 = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
schemaObject.required.forEach((prop) => {
|
schemaObject.required.forEach((prop) => {
|
||||||
@ -60,32 +49,12 @@ async function main() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
schemaObject.required = [
|
|
||||||
...new Set(schemaObject.required.concat(['id', 'type'])),
|
|
||||||
];
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if we are generating types for an invocation output
|
// Check if we are generating types for an invocation output
|
||||||
const isInvocationOutputPath = metadata.path.match(
|
if ('class' in schemaObject && schemaObject.class === 'output') {
|
||||||
/^#\/components\/schemas\/\w*Output$/
|
// modify output types
|
||||||
);
|
|
||||||
|
|
||||||
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}`
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user