Skip to content

Commit

Permalink
fix: imports from #nuxt-api-party
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Aug 18, 2023
1 parent 5c5b308 commit 7ac9d90
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,33 +184,34 @@ 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 => `
export declare const ${getRawComposableName(i)}: ${schemaEndpointIds.includes(i) ? `$OpenApi<${pascalCase(i)}Paths>` : '$AnyApi'}
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
Expand Down
1 change: 1 addition & 0 deletions src/openapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export async function generateTypes(
})
}
catch {
// TODO: Use `Record<string, never>`?
types = `
export type paths = Record<string, any>
export type webhooks = Record<string, any>
Expand Down

0 comments on commit 7ac9d90

Please sign in to comment.