Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use openapi-core to bundle definition instead of json-schema-ref-parser #1500

Merged
merged 12 commits into from
Apr 8, 2021
Merged
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- '10'
- '12'
cache:
directories:
- "~/.cache"
Expand Down
4 changes: 2 additions & 2 deletions demo/webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
: {},
},

Expand Down
10,410 changes: 4,043 additions & 6,367 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,14 +134,14 @@
"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",
"decko": "^1.2.0",
"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",
Expand Down
1 change: 1 addition & 0 deletions src/components/ApiLogo/styled.elements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
2 changes: 1 addition & 1 deletion src/components/SideMenu/styled.elements.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
28 changes: 20 additions & 8 deletions src/utils/loadAndBundleSpec.ts
Original file line number Diff line number Diff line change
@@ -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;
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 (spec.swagger !== undefined) {
return convertSwagger2OpenAPI(spec);
if (typeof specUrlOrObject === 'object' && specUrlOrObject !== null) {
bundleOpts['doc'] = {
source: { absoluteRef: '' } as Source,
parsed: specUrlOrObject
} as Document
} else {
return spec;
bundleOpts['ref'] = specUrlOrObject;
}

const { bundle: { parsed } } = await bundle(bundleOpts);
return parsed.swagger !== undefined ? convertSwagger2OpenAPI(parsed) : parsed;
}

export function convertSwagger2OpenAPI(spec: any): Promise<OpenAPISpec> {
Expand Down
7 changes: 0 additions & 7 deletions webpack.config.ts
Original file line number Diff line number Diff line change
@@ -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')({
Expand Down Expand Up @@ -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',
Expand Down