Skip to content

Commit

Permalink
fix: interop default export
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed May 13, 2024
1 parent 9297421 commit f9098dd
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/openapi.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { resolve } from 'pathe'
import { useNuxt } from '@nuxt/kit'
import type { OpenAPI3, OpenAPITSOptions } from 'openapi-typescript'
import openAPITS, { astToString } from 'openapi-typescript'
import type { ApiEndpoint } from './module'

declare module 'openapi-typescript' {
Expand Down Expand Up @@ -36,6 +35,9 @@ async function generateSchemaTypes(options: {
openAPITSOptions?: OpenAPITSOptions
},
) {
// openapi-typescript < 7 does not have named exports
const openAPITS = await interopDefault(import('openapi-typescript'))
const { astToString } = await import('openapi-typescript')
const schema = await resolveSchema(options.endpoint)

try {
Expand Down Expand Up @@ -89,3 +91,11 @@ function isValidUrl(url: string) {
return false
}
}

async function interopDefault<T>(
m: T | Promise<T>,
): Promise<T extends { default: infer U } ? U : T> {
const resolved = await m
// eslint-disable-next-line @typescript-eslint/no-explicit-any
return (resolved as any).default || resolved
}

0 comments on commit f9098dd

Please sign in to comment.