|
1 | 1 | import type { OpenAPI3, OpenAPITSOptions } from 'openapi-typescript' |
2 | 2 | import type { EndpointConfiguration } from './module' |
| 3 | +import { pathToFileURL } from 'node:url' |
3 | 4 | import { useNuxt } from '@nuxt/kit' |
4 | | -import { resolve } from 'pathe' |
| 5 | +import { isAbsolute, resolve } from 'pathe' |
5 | 6 | import { pascalCase } from 'scule' |
6 | 7 |
|
7 | 8 | /** @deprecated Hooks should be used instead */ |
@@ -193,26 +194,27 @@ export type operations = Record<string, never> |
193 | 194 | } |
194 | 195 |
|
195 | 196 | async function resolveSchema(id: string, { schema }: SchemaEndpoint): Promise<string | URL | OpenAPI3> { |
196 | | - const nuxt = useNuxt() |
197 | | - |
198 | 197 | if (typeof schema === 'function') { |
199 | 198 | console.warn(`[nuxt-api-party] Passing a function to "apiParty.endpoints.${id}.schema" is deprecated. Use the "api-party:extend" hook instead.`) |
200 | 199 | return await schema() |
201 | 200 | } |
202 | 201 |
|
203 | | - if (typeof schema === 'string' && !isValidUrl(schema)) |
204 | | - return new URL(resolve(nuxt.options.rootDir, schema), import.meta.url) |
| 202 | + if (typeof schema === 'string') { |
| 203 | + if (/^https?:\/\//i.test(schema)) |
| 204 | + return schema |
205 | 205 |
|
206 | | - return schema! |
207 | | -} |
| 206 | + if (schema.startsWith('file://')) |
| 207 | + return new URL(schema) |
208 | 208 |
|
209 | | -function isValidUrl(url: string) { |
210 | | - try { |
211 | | - return Boolean(new URL(url)) |
212 | | - } |
213 | | - catch { |
214 | | - return false |
| 209 | + const nuxt = useNuxt() |
| 210 | + const resolvedPath = isAbsolute(schema) |
| 211 | + ? schema |
| 212 | + : resolve(nuxt.options.rootDir, schema) |
| 213 | + |
| 214 | + return pathToFileURL(resolvedPath) |
215 | 215 | } |
| 216 | + |
| 217 | + return schema! |
216 | 218 | } |
217 | 219 |
|
218 | 220 | async function interopDefault<T>( |
|
0 commit comments