Skip to content

Commit e62991c

Browse files
psychedelicioushipsterusername
authored andcommitted
feat(ui): remove superseded logic in typegen.js
This logic is no longer needed thanks to the changes introduced during the pydantic v2 upgrade.
1 parent 785d584 commit e62991c

1 file changed

Lines changed: 2 additions & 44 deletions

File tree

invokeai/frontend/web/scripts/typegen.js

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,19 @@
11
import fs from 'node:fs';
22
import openapiTS from 'openapi-typescript';
3-
import { COLORS } from './colors.js';
43

54
const OPENAPI_URL = 'http://127.0.0.1:9090/openapi.json';
65
const OUTPUT_FILE = 'src/services/api/schema.d.ts';
76

87
async function main() {
98
process.stdout.write(
10-
`Generating types "${OPENAPI_URL}" --> "${OUTPUT_FILE}"...\n\n`
9+
`Generating types "${OPENAPI_URL}" --> "${OUTPUT_FILE}"...`
1110
);
1211
const types = await openapiTS(OPENAPI_URL, {
1312
exportType: true,
14-
transform: (schemaObject, metadata) => {
13+
transform: (schemaObject) => {
1514
if ('format' in schemaObject && schemaObject.format === 'binary') {
1615
return schemaObject.nullable ? 'Blob | null' : 'Blob';
1716
}
18-
19-
/**
20-
* Because invocations may have required fields that accept connection input, the generated
21-
* types may be incorrect.
22-
*
23-
* For example, the ImageResizeInvocation has a required `image` field, but because it accepts
24-
* connection input, it should be optional on instantiation of the field.
25-
*
26-
* To handle this, the schema exposes an `input` property that can be used to determine if the
27-
* field accepts connection input. If it does, we can make the field optional.
28-
*/
29-
30-
if ('class' in schemaObject && schemaObject.class === 'invocation') {
31-
// We only want to make fields optional if they are required
32-
if (!Array.isArray(schemaObject?.required)) {
33-
schemaObject.required = [];
34-
}
35-
36-
schemaObject.required.forEach((prop) => {
37-
const acceptsConnection = ['any', 'connection'].includes(
38-
schemaObject.properties?.[prop]?.['input']
39-
);
40-
41-
if (acceptsConnection) {
42-
// remove this prop from the required array
43-
const invocationName = metadata.path.split('/').pop();
44-
console.log(
45-
`Making connectable field optional: ${COLORS.fg.green}${invocationName}.${COLORS.fg.cyan}${prop}${COLORS.reset}`
46-
);
47-
schemaObject.required = schemaObject.required.filter(
48-
(r) => r !== prop
49-
);
50-
}
51-
});
52-
return;
53-
}
54-
55-
// Check if we are generating types for an invocation output
56-
if ('class' in schemaObject && schemaObject.class === 'output') {
57-
// modify output types
58-
}
5917
},
6018
});
6119
fs.writeFileSync(OUTPUT_FILE, types);

0 commit comments

Comments
 (0)