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 language: node_js
node_js: node_js:
- '10' - '12'
cache: cache:
directories: directories:
- "~/.cache" - "~/.cache"

9286
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" "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",

View File

@ -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>;

View File

@ -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';

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 */ /* 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> {

View File

@ -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',