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: {
|
||||
extensions: ['.ts', '.tsx', '.js', '.json'],
|
||||
alias:
|
||||
mode !== 'production'
|
||||
? {
|
||||
'react-dom': '@hot-loader/react-dom',
|
||||
alias: {
|
||||
fs: root('fs.mock.js'),
|
||||
...(mode !== 'production' && { 'react-dom': '@hot-loader/react-dom' })
|
||||
}
|
||||
: {},
|
||||
},
|
||||
|
||||
node: {
|
||||
fs: 'empty',
|
||||
},
|
||||
|
||||
performance: false,
|
||||
|
||||
externals: {
|
||||
esprima: 'esprima',
|
||||
'node-fetch': 'null',
|
||||
|
|
31965
package-lock.json
generated
31965
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"
|
||||
},
|
||||
"dependencies": {
|
||||
"@redocly/openapi-core": "^1.0.0-beta.29",
|
||||
"@redocly/react-dropdown-aria": "^2.0.11",
|
||||
"@types/node": "^13.11.1",
|
||||
"classnames": "^2.2.6",
|
||||
|
@ -141,7 +142,6 @@
|
|||
"dompurify": "^2.0.12",
|
||||
"eventemitter3": "^4.0.4",
|
||||
"json-pointer": "^0.6.0",
|
||||
"json-schema-ref-parser": "^6.1.0",
|
||||
"lunr": "2.3.8",
|
||||
"mark.js": "^8.11.1",
|
||||
"marked": "^0.7.0",
|
||||
|
|
|
@ -1,19 +1,29 @@
|
|||
import * as JsonSchemaRefParser from 'json-schema-ref-parser';
|
||||
/* tslint:disable-next-line:no-implicit-dependencies */
|
||||
import { convertObj } from 'swagger2openapi';
|
||||
import { OpenAPISpec } from '../types';
|
||||
import { Source, Document, bundle, loadConfig } from '@redocly/openapi-core';
|
||||
|
||||
export async function loadAndBundleSpec(specUrlOrObject: object | string): Promise<OpenAPISpec> {
|
||||
const parser = new JsonSchemaRefParser();
|
||||
const spec = (await parser.bundle(specUrlOrObject, {
|
||||
resolve: { http: { withCredentials: false } },
|
||||
} as object)) as any;
|
||||
|
||||
if (spec.swagger !== undefined) {
|
||||
return convertSwagger2OpenAPI(spec);
|
||||
const isNode = typeof process !== 'undefined' && process.versions != null && process.versions.node != null;
|
||||
let bundleRef;
|
||||
const config = await loadConfig();
|
||||
if (typeof specUrlOrObject === 'object' && specUrlOrObject !== null) {
|
||||
bundleRef = {
|
||||
source: { absoluteRef: '' } as Source,
|
||||
parsed: specUrlOrObject
|
||||
} as Document
|
||||
} 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> {
|
||||
|
|
Loading…
Reference in New Issue
Block a user