Add validations to RedocStandalone component

This commit is contained in:
Roman Hotsiy 2017-11-20 18:03:11 +02:00
parent c2f82cdc8b
commit 8d84fa669c
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
2 changed files with 23 additions and 1 deletions

View File

@ -16,6 +16,26 @@ export interface RedocStandaloneProps {
} }
export class RedocStandalone extends React.Component<RedocStandaloneProps> { export class RedocStandalone extends React.Component<RedocStandaloneProps> {
static propTypes = {
spec: (props, _, componentName) => {
if (!props.spec && !props.specUrl) {
return new Error(
`One of props 'spec' or 'specUrlurl' was not specified in '${componentName}'.`,
);
}
return null;
},
specUrl: (props, _, componentName) => {
if (!props.spec && !props.specUrl) {
return new Error(
`One of props 'spec' or 'specUrl' was not specified in '${componentName}'.`,
);
}
return null;
},
};
render() { render() {
const { spec, specUrl, options } = this.props; const { spec, specUrl, options } = this.props;

View File

@ -33,7 +33,9 @@ export function init(
throw new Error('"element" argument is not provided and <redoc> tag is not found on the page'); throw new Error('"element" argument is not provided and <redoc> tag is not found on the page');
} }
let specUrl, spec; let specUrl: string | undefined;
let spec: object | undefined;
if (typeof specOrSpecUrl === 'string') { if (typeof specOrSpecUrl === 'string') {
specUrl = specOrSpecUrl; specUrl = specOrSpecUrl;
} else if (typeof specOrSpecUrl === 'object') { } else if (typeof specOrSpecUrl === 'object') {