mirror of
https://github.com/Redocly/redoc.git
synced 2025-08-07 13:44:54 +03:00
chore: use openapi-core to bundle definition instead of json-schema-ref-parser
This commit is contained in:
parent
e5644ee67a
commit
2fbe8e30cd
6
demo/fs.mock.js
Normal file
6
demo/fs.mock.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
module.exports = {
|
||||||
|
promises: {
|
||||||
|
readFile () {}
|
||||||
|
},
|
||||||
|
existsSync () {},
|
||||||
|
}
|
|
@ -73,20 +73,12 @@ export default (env: { playground?: boolean; bench?: boolean } = {}, { mode }) =
|
||||||
|
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['.ts', '.tsx', '.js', '.json'],
|
extensions: ['.ts', '.tsx', '.js', '.json'],
|
||||||
alias:
|
alias: {
|
||||||
mode !== 'production'
|
fs: root('fs.mock.js'),
|
||||||
? {
|
...(mode !== 'production' && { 'react-dom': '@hot-loader/react-dom' })
|
||||||
'react-dom': '@hot-loader/react-dom',
|
}
|
||||||
}
|
|
||||||
: {},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
node: {
|
|
||||||
fs: 'empty',
|
|
||||||
},
|
|
||||||
|
|
||||||
performance: false,
|
performance: false,
|
||||||
|
|
||||||
externals: {
|
externals: {
|
||||||
esprima: 'esprima',
|
esprima: 'esprima',
|
||||||
'node-fetch': 'null',
|
'node-fetch': 'null',
|
||||||
|
|
31825
package-lock.json
generated
31825
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
|
@ -134,6 +134,7 @@
|
||||||
"styled-components": "^4.1.1 || ^5.1.1"
|
"styled-components": "^4.1.1 || ^5.1.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@redocly/openapi-core": "^1.0.0-beta.29",
|
||||||
"@redocly/react-dropdown-aria": "^2.0.11",
|
"@redocly/react-dropdown-aria": "^2.0.11",
|
||||||
"@types/node": "^13.11.1",
|
"@types/node": "^13.11.1",
|
||||||
"classnames": "^2.2.6",
|
"classnames": "^2.2.6",
|
||||||
|
@ -141,7 +142,6 @@
|
||||||
"dompurify": "^2.0.12",
|
"dompurify": "^2.0.12",
|
||||||
"eventemitter3": "^4.0.4",
|
"eventemitter3": "^4.0.4",
|
||||||
"json-pointer": "^0.6.0",
|
"json-pointer": "^0.6.0",
|
||||||
"json-schema-ref-parser": "^6.1.0",
|
|
||||||
"lunr": "2.3.8",
|
"lunr": "2.3.8",
|
||||||
"mark.js": "^8.11.1",
|
"mark.js": "^8.11.1",
|
||||||
"marked": "^0.7.0",
|
"marked": "^0.7.0",
|
||||||
|
|
|
@ -1,19 +1,29 @@
|
||||||
import * as JsonSchemaRefParser from 'json-schema-ref-parser';
|
|
||||||
/* tslint:disable-next-line:no-implicit-dependencies */
|
/* tslint:disable-next-line:no-implicit-dependencies */
|
||||||
import { convertObj } from 'swagger2openapi';
|
import { convertObj } from 'swagger2openapi';
|
||||||
import { OpenAPISpec } from '../types';
|
import { OpenAPISpec } from '../types';
|
||||||
|
import { Source, Document, bundle, loadConfig } from '@redocly/openapi-core';
|
||||||
|
|
||||||
export async function loadAndBundleSpec(specUrlOrObject: object | string): Promise<OpenAPISpec> {
|
export async function loadAndBundleSpec(specUrlOrObject: object | string): Promise<OpenAPISpec> {
|
||||||
const parser = new JsonSchemaRefParser();
|
const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
|
||||||
const spec = (await parser.bundle(specUrlOrObject, {
|
let bundleRef;
|
||||||
resolve: { http: { withCredentials: false } },
|
const config = await loadConfig();
|
||||||
} as object)) as any;
|
if (typeof specUrlOrObject === 'object' && specUrlOrObject !== null) {
|
||||||
|
bundleRef = {
|
||||||
if (spec.swagger !== undefined) {
|
source: { absoluteRef: '' } as Source,
|
||||||
return convertSwagger2OpenAPI(spec);
|
parsed: specUrlOrObject
|
||||||
|
} as Document
|
||||||
} else {
|
} else {
|
||||||
return spec;
|
config.resolve.http.customFetch = fetch;
|
||||||
|
bundleRef = specUrlOrObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { bundle: { parsed } } = await bundle({
|
||||||
|
ref: bundleRef,
|
||||||
|
config,
|
||||||
|
base: isNode ? process.cwd() : window.location.href
|
||||||
|
});
|
||||||
|
|
||||||
|
return parsed.swagger !== undefined ? convertSwagger2OpenAPI(parsed) : parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertSwagger2OpenAPI(spec: any): Promise<OpenAPISpec> {
|
export function convertSwagger2OpenAPI(spec: any): Promise<OpenAPISpec> {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user