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:
Andriy Leliv 2021-04-08 15:49:15 +03:00 committed by GitHub
parent e5644ee67a
commit 503394655d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 3515 additions and 5833 deletions

View File

@ -1,6 +1,6 @@
language: node_js
node_js:
- '10'
- '12'
cache:
directories:
- "~/.cache"

View File

@ -76,8 +76,8 @@ export default (env: { playground?: boolean; bench?: boolean } = {}, { mode }) =
alias:
mode !== 'production'
? {
'react-dom': '@hot-loader/react-dom',
}
'react-dom': '@hot-loader/react-dom',
}
: {},
},

9298
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -134,6 +134,7 @@
"styled-components": "^4.1.1 || ^5.1.1"
},
"dependencies": {
"@redocly/openapi-core": "^1.0.0-beta.42",
"@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",

View File

@ -17,4 +17,5 @@ const Link = styled.a`
display: inline-block;
`;
// eslint-disable-next-line react/display-name
export const LinkWrap = url => Component => <Link href={url}>{Component}</Link>;

View File

@ -1,4 +1,4 @@
import * as classnames from 'classnames';
import { default as classnames } from 'classnames';
import { darken } from 'polished';
import { deprecatedCss, ShelfIcon } from '../../common-elements';

View File

@ -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 */
import { convertObj } from 'swagger2openapi';
import { OpenAPISpec } from '../types';
import { IS_BROWSER } from './dom';
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);
} else {
return spec;
const config = new Config({});
const bundleOpts = {
config,
base: IS_BROWSER ? window.location.href : process.cwd()
}
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> {

View File

@ -1,7 +1,6 @@
/* tslint:disable:no-implicit-dependencies */
import ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
import * as webpack from 'webpack';
import * as path from 'path';
const nodeExternals = require('webpack-node-externals')({
@ -41,23 +40,17 @@ export default (env: { standalone?: boolean } = {}, { mode }) => ({
libraryTarget: 'umd',
globalObject: 'this',
},
devtool: 'source-map',
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
},
node: {
fs: 'empty',
},
performance: false,
optimization: {
minimize: !!env.standalone,
},
externals: env.standalone
? {
esprima: 'esprima',