Convert swagger 2.0 to OpenAPI v3 (#128)

* Convert swagger 2.0 to OpenAPI 3

* Format
This commit is contained in:
Samy Pessé
2024-01-31 15:46:42 +01:00
committed by GitHub
parent f8fde8cec8
commit 75876474a2
4 changed files with 30 additions and 2 deletions
BIN
View File
Binary file not shown.
+15 -2
View File
@@ -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)
+2
View File
@@ -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",
+13
View File
@@ -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,