From f9098dd3d082fd773e7710074bdf0652da7a17d2 Mon Sep 17 00:00:00 2001 From: Johann Schopplich Date: Mon, 13 May 2024 12:09:37 +0200 Subject: [PATCH] fix: interop default export --- src/openapi.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/openapi.ts b/src/openapi.ts index 130c208..acbabf3 100644 --- a/src/openapi.ts +++ b/src/openapi.ts @@ -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' { @@ -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 { @@ -89,3 +91,11 @@ function isValidUrl(url: string) { return false } } + +async function interopDefault( + m: T | Promise, +): Promise { + const resolved = await m + // eslint-disable-next-line @typescript-eslint/no-explicit-any + return (resolved as any).default || resolved +}