(projectPath: string, schema: string)
| 68 | } |
| 69 | |
| 70 | export async function generateJsonInterfaces(projectPath: string, schema: string): Promise<void> { |
| 71 | const typesDir = path.join(projectPath, TYPE_ROOT_DIR); |
| 72 | const jsonObjects = getAllJsonObjects(schema); |
| 73 | const jsonInterfaces = jsonObjects.map((r) => { |
| 74 | const object = setJsonObjectType(r, jsonObjects); |
| 75 | const fields = processFields('jsonField', object.name, object.fields); |
| 76 | return { |
| 77 | interfaceName: object.name, |
| 78 | fields, |
| 79 | }; |
| 80 | }); |
| 81 | |
| 82 | if (jsonInterfaces.length !== 0) { |
| 83 | const interfaceTemplate = { |
| 84 | props: { |
| 85 | jsonInterfaces, |
| 86 | }, |
| 87 | helper: { |
| 88 | upperFirst, |
| 89 | }, |
| 90 | }; |
| 91 | try { |
| 92 | await renderTemplate(INTERFACE_TEMPLATE_PATH, path.join(typesDir, `interfaces.ts`), interfaceTemplate); |
| 93 | exportTypes.interfaces = true; |
| 94 | } catch (e) { |
| 95 | throw new Error(`Codegen failed for json interface.`, {cause: e}); |
| 96 | } |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | export async function generateEnums(projectPath: string, schema: string): Promise<void> { |
| 101 | const typesDir = path.join(projectPath, TYPE_ROOT_DIR); |
no test coverage detected