import fs from 'node:fs'; import { mkdir } from 'node:fs/promises'; import { dirname, resolve } from 'node:path'; import YAML from 'yaml'; import openapiTS, { astToString } from 'openapi-typescript'; const schemaRequest = await fetch('https://authentik.olsen.cloud/api/v3/schema/'); if (!schemaRequest.ok) { console.error(schemaRequest.status, schemaRequest.statusText); throw new Error('Failed to fetch schema'); } const schemaYaml = await schemaRequest.text(); const schema = YAML.parse(schemaYaml); const ast = await openapiTS(schema); const contents = astToString(ast); const targetLocation = resolve(import.meta.dirname, '..', 'src', 'clients', 'authentik', 'authentik.types.d.ts'); await mkdir(dirname(targetLocation), { recursive: true }); fs.writeFileSync( targetLocation, ['// This file is generated by scripts/create-clients.ts', '/* eslint-disable */', contents].join('\n'), );