mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-24 19:32:07 +00:00
Convert swagger 2.0 to OpenAPI v3 (#128)
* Convert swagger 2.0 to OpenAPI 3 * Format
This commit is contained in:
+15
-2
@@ -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)
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user