diff --git a/bun.lockb b/bun.lockb index d9132a161..d112f7f88 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/next.config.js b/next.config.js index 6af66e9ab..2cff33ce7 100644 --- a/next.config.js +++ b/next.config.js @@ -7,11 +7,24 @@ module.exports = withSentryConfig( SENTRY_DSN: process.env.SENTRY_DSN ?? '', SENTRY_ENVIRONMENT: process.env.SENTRY_ENVIRONMENT ?? 'development', }, + + webpack(config) { + config.resolve.fallback = { + ...config.resolve.fallback, + + // Required for `swagger2openapi` to work: + fs: false, + path: false, + http: false, + }; + + return config; + }, }, { silent: true, - org: 'gitbook-x', - project: 'gitbook-open', + org: process.env.SENTRY_ORG, + project: process.env.SENTRY_PROJECT, }, { // Upload a larger set of source maps for prettier stack traces (increases build time) diff --git a/package.json b/package.json index 4a71b97ea..ed8a1b603 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "remark-rehype": "^11.1.0", "server-only": "^0.0.1", "shikiji": "^0.8.0", + "swagger2openapi": "^7.0.8", "tailwind-merge": "^2.2.0", "tailwind-shades": "^1.1.2", "unified": "^11.0.4", @@ -72,6 +73,7 @@ "@types/psi": "^4.1.6", "@types/react": "^18", "@types/react-dom": "^18", + "@types/swagger2openapi": "^7.0.4", "autoprefixer": "^10", "eslint": "^8", "eslint-config-next": "13.5.6", diff --git a/src/lib/openapi.ts b/src/lib/openapi.ts index 98c2a2212..b7e4352f0 100644 --- a/src/lib/openapi.ts +++ b/src/lib/openapi.ts @@ -9,6 +9,7 @@ import rehypeSanitize from 'rehype-sanitize'; import rehypeStringify from 'rehype-stringify'; import remarkParse from 'remark-parse'; import remarkRehype from 'remark-rehype'; +import swagger2openapi, { ConvertOutputOptions } from 'swagger2openapi'; import { unified } from 'unified'; import { cache, parseCacheResponse, noCacheFetchOptions } from '@/lib/cache'; @@ -64,6 +65,18 @@ const fetcher: OpenAPIFetcher = { } } + // @ts-ignore + if (data && data.swagger) { + // Convert Swagger 2.0 to OpenAPI 3.0 + // @ts-ignore + const result = (await swagger2openapi.convertObj(data, { + resolve: false, + resolveInternal: false, + })) as ConvertOutputOptions; + + data = result.openapi; + } + return { ...parseCacheResponse(response), data,