mirror of
				https://github.com/Redocly/redoc.git
				synced 2025-10-31 07:47:29 +03:00 
			
		
		
		
	Add validations to RedocStandalone component
This commit is contained in:
		
							parent
							
								
									c2f82cdc8b
								
							
						
					
					
						commit
						8d84fa669c
					
				|  | @ -16,6 +16,26 @@ export interface 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() { | ||||
|     const { spec, specUrl, options } = this.props; | ||||
| 
 | ||||
|  |  | |||
|  | @ -33,7 +33,9 @@ export function init( | |||
|     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') { | ||||
|     specUrl = specOrSpecUrl; | ||||
|   } else if (typeof specOrSpecUrl === 'object') { | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user