diff --git a/src/module.ts b/src/module.ts index 2edb931..c3d8d90 100644 --- a/src/module.ts +++ b/src/module.ts @@ -184,15 +184,11 @@ export const ${getDataComposableName(i)} = (...args) => _useApiData('${i}', ...a // Use generated types for generated composables for // (1) Nuxt auto-imports // (2) global import from `#nuxt-api-party` - addTemplate({ - filename: `module/${moduleName}-imports.d.ts`, - getContents() { - return ` + const typesSchema = ` // Generated by ${moduleName} -import type { $Api, $AnyApi, $OpenApi, AnyApiFetchOptions } from '${relativeTo('runtime/composables/$api')}' -import type { UseApiData, UseAnyApiData, UseOpenApiData, UseAnyApiDataOptions } from '${relativeTo('runtime/composables/useApiData')}' +import type { $AnyApi, $OpenApi } from '${relativeTo('runtime/composables/$api')}' +import type { UseAnyApiData, UseOpenApiData } from '${relativeTo('runtime/composables/useApiData')}' -export type { $Api, $AnyApi, $OpenApi, AnyApiFetchOptions, UseApiData, UseAnyApiData, UseOpenApiData, UseAnyApiDataOptions } ${schemaEndpointIds.map(i => `import type { paths as ${pascalCase(i)}Paths } from '#${moduleName}/${i}'`).join('')} ${endpointKeys.map(i => ` @@ -200,17 +196,22 @@ export declare const ${getRawComposableName(i)}: ${schemaEndpointIds.includes(i) export declare const ${getDataComposableName(i)}: ${schemaEndpointIds.includes(i) ? `UseOpenApiData<${pascalCase(i)}Paths>` : 'UseAnyApiData'} `.trimStart()).join('').trimEnd()} `.trimStart() + + // Add types for Nuxt auto-imports + addTemplate({ + filename: `module/${moduleName}-imports.d.ts`, + getContents() { + return typesSchema }, }) - // Add global `#nuxt-api-party` and OpenAPI endpoint types + // Add types for global aliases addTemplate({ filename: `module/${moduleName}.d.ts`, async getContents() { return ` -// Generated by ${moduleName} declare module '#${moduleName}' { - export * from './${moduleName}-imports' +${typesSchema.replace(/^/gm, ' ').trimEnd()} } ${schemaEndpointIds.length diff --git a/src/openapi.ts b/src/openapi.ts index 43d81cc..2527990 100644 --- a/src/openapi.ts +++ b/src/openapi.ts @@ -33,6 +33,7 @@ export async function generateTypes( }) } catch { + // TODO: Use `Record`? types = ` export type paths = Record export type webhooks = Record