Update Redoc Standalone API

This commit is contained in:
Roman Hotsiy 2017-11-20 15:02:35 +02:00
parent 1dabeebb3d
commit 6fbd47b340
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
2 changed files with 12 additions and 11 deletions

View File

@ -8,7 +8,8 @@ import { ErrorBoundary } from './ErrorBoundary';
import { Redoc } from './Redoc/Redoc';
export interface RedocStandaloneProps {
specOrSpecUrl: string | object;
spec?: object;
specUrl?: string;
options?: {
theme?: ThemeInterface;
};
@ -16,15 +17,7 @@ export interface RedocStandaloneProps {
export class RedocStandalone extends React.Component<RedocStandaloneProps> {
render() {
const { specOrSpecUrl, options } = this.props;
let specUrl;
let spec;
if (typeof specOrSpecUrl === 'string') {
specUrl = specOrSpecUrl;
} else if (typeof specOrSpecUrl === 'object') {
spec = specOrSpecUrl;
}
const { spec, specUrl, options } = this.props;
return (
<ErrorBoundary>

View File

@ -33,11 +33,19 @@ export function init(
throw new Error('"element" argument is not provided and <redoc> tag is not found on the page');
}
let specUrl, spec;
if (typeof specOrSpecUrl === 'string') {
specUrl = specOrSpecUrl;
} else if (typeof specOrSpecUrl === 'object') {
spec = specOrSpecUrl;
}
render(
React.createElement(
RedocStandalone,
{
specOrSpecUrl,
spec,
specUrl,
options: { ...options, ...parseOptionsFromElement(element) },
},
['Loading...'],