mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-22 08:36:33 +03:00
chore: use openapi-core to bundle definition instead of json-schema-ref-parser (#1500)
* chore: use openapi-core to bundle definition instead of json-schema-ref-parser * chore: update: root and demo webpack configs * chore: refactor loadAndBundleSpec * chore: update vesions: openapi-core, redoc * chore: rolled back webpack.config(s) to previous version * chore: changed the way of creating core Config for bundling definition * fix: disable eslint react/display-name * fix: update nodejs version to 12 in travis config * chore: optimize verification: browser or server * chore: add fetch only for browser * Update src/utils/loadAndBundleSpec.ts * chore: isBrowser verification improvment Co-authored-by: Roman Hotsiy <gotsijroman@gmail.com>
This commit is contained in:
parent
e5644ee67a
commit
503394655d
|
@ -1,6 +1,6 @@
|
||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js:
|
||||||
- '10'
|
- '12'
|
||||||
cache:
|
cache:
|
||||||
directories:
|
directories:
|
||||||
- "~/.cache"
|
- "~/.cache"
|
||||||
|
|
|
@ -76,8 +76,8 @@ export default (env: { playground?: boolean; bench?: boolean } = {}, { mode }) =
|
||||||
alias:
|
alias:
|
||||||
mode !== 'production'
|
mode !== 'production'
|
||||||
? {
|
? {
|
||||||
'react-dom': '@hot-loader/react-dom',
|
'react-dom': '@hot-loader/react-dom',
|
||||||
}
|
}
|
||||||
: {},
|
: {},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
9298
package-lock.json
generated
9298
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.42",
|
||||||
"@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",
|
||||||
|
|
|
@ -17,4 +17,5 @@ const Link = styled.a`
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
// eslint-disable-next-line react/display-name
|
||||||
export const LinkWrap = url => Component => <Link href={url}>{Component}</Link>;
|
export const LinkWrap = url => Component => <Link href={url}>{Component}</Link>;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import * as classnames from 'classnames';
|
import { default as classnames } from 'classnames';
|
||||||
import { darken } from 'polished';
|
import { darken } from 'polished';
|
||||||
|
|
||||||
import { deprecatedCss, ShelfIcon } from '../../common-elements';
|
import { deprecatedCss, ShelfIcon } from '../../common-elements';
|
||||||
|
|
|
@ -1,19 +1,31 @@
|
||||||
import * as JsonSchemaRefParser from 'json-schema-ref-parser';
|
import { Source, Document, bundle, Config } from '@redocly/openapi-core';
|
||||||
/* 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 { IS_BROWSER } from './dom';
|
||||||
|
|
||||||
export async function loadAndBundleSpec(specUrlOrObject: object | string): Promise<OpenAPISpec> {
|
export async function loadAndBundleSpec(specUrlOrObject: object | string): Promise<OpenAPISpec> {
|
||||||
const parser = new JsonSchemaRefParser();
|
const config = new Config({});
|
||||||
const spec = (await parser.bundle(specUrlOrObject, {
|
const bundleOpts = {
|
||||||
resolve: { http: { withCredentials: false } },
|
config,
|
||||||
} as object)) as any;
|
base: IS_BROWSER ? window.location.href : process.cwd()
|
||||||
|
|
||||||
if (spec.swagger !== undefined) {
|
|
||||||
return convertSwagger2OpenAPI(spec);
|
|
||||||
} else {
|
|
||||||
return spec;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (IS_BROWSER) {
|
||||||
|
config.resolve.http.customFetch = global.fetch;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof specUrlOrObject === 'object' && specUrlOrObject !== null) {
|
||||||
|
bundleOpts['doc'] = {
|
||||||
|
source: { absoluteRef: '' } as Source,
|
||||||
|
parsed: specUrlOrObject
|
||||||
|
} as Document
|
||||||
|
} else {
|
||||||
|
bundleOpts['ref'] = specUrlOrObject;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { bundle: { parsed } } = await bundle(bundleOpts);
|
||||||
|
return parsed.swagger !== undefined ? convertSwagger2OpenAPI(parsed) : parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function convertSwagger2OpenAPI(spec: any): Promise<OpenAPISpec> {
|
export function convertSwagger2OpenAPI(spec: any): Promise<OpenAPISpec> {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
/* tslint:disable:no-implicit-dependencies */
|
/* tslint:disable:no-implicit-dependencies */
|
||||||
import ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
import ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
|
||||||
import * as webpack from 'webpack';
|
import * as webpack from 'webpack';
|
||||||
|
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
|
|
||||||
const nodeExternals = require('webpack-node-externals')({
|
const nodeExternals = require('webpack-node-externals')({
|
||||||
|
@ -41,23 +40,17 @@ export default (env: { standalone?: boolean } = {}, { mode }) => ({
|
||||||
libraryTarget: 'umd',
|
libraryTarget: 'umd',
|
||||||
globalObject: 'this',
|
globalObject: 'this',
|
||||||
},
|
},
|
||||||
|
|
||||||
devtool: 'source-map',
|
devtool: 'source-map',
|
||||||
|
|
||||||
resolve: {
|
resolve: {
|
||||||
extensions: ['.ts', '.tsx', '.js', '.json'],
|
extensions: ['.ts', '.tsx', '.js', '.json'],
|
||||||
},
|
},
|
||||||
|
|
||||||
node: {
|
node: {
|
||||||
fs: 'empty',
|
fs: 'empty',
|
||||||
},
|
},
|
||||||
|
|
||||||
performance: false,
|
performance: false,
|
||||||
|
|
||||||
optimization: {
|
optimization: {
|
||||||
minimize: !!env.standalone,
|
minimize: !!env.standalone,
|
||||||
},
|
},
|
||||||
|
|
||||||
externals: env.standalone
|
externals: env.standalone
|
||||||
? {
|
? {
|
||||||
esprima: 'esprima',
|
esprima: 'esprima',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user