@@ -11,12 +11,12 @@ import {useAuthSessionStorage} from '../hooks/useAuthSessionStorage';
1111import { Column , SecurityApiKey , SecurityOAuthImplicit , SecurityOAuthInline } from '.' ;
1212
1313type SecurityProps = {
14- security : OpenAPIV3 . SecuritySchemeObject [ ] ;
14+ security ? : OpenAPIV3 . SecuritySchemeObject [ ] ;
1515 projectName : string ;
1616} ;
1717
1818export const Security : React . FC < SecurityProps > = ( props ) => {
19- const { security} = props ;
19+ const { security = [ ] } = props ;
2020 const {
2121 isOpen,
2222 close,
@@ -31,8 +31,8 @@ export const Security: React.FC<SecurityProps> = (props) => {
3131 hasAnyAuthorization,
3232 } = useEnhance ( props ) ;
3333
34- if ( ! activeSecurityTab ) {
35- throw new Error ( ) ;
34+ if ( ! security || ! security . length || ! activeSecurityTab ) {
35+ return null ;
3636 }
3737
3838 return (
@@ -73,15 +73,18 @@ export const Security: React.FC<SecurityProps> = (props) => {
7373} ;
7474
7575function useEnhance ( { projectName, security} : SecurityProps ) {
76+ security = security || [ ] ;
77+
78+ const initialType : V3SecurityType | undefined = security [ 0 ] ?. type ;
7679 const [ isOpen , setOpen ] = useState ( false ) ;
7780 const [ auth , setAuth ] = useAuthSessionStorage ( {
7881 projectName,
79- initialType : security [ 0 ] . type ,
82+ initialType,
8083 } ) ;
8184 const hasAnyAuthorization = Boolean ( auth . value ) ;
8285 const [ activeType , setActiveType ] = useState ( auth . type ) ;
8386 const activeSecurityTab = useMemo (
84- ( ) => security . find ( ( { type} ) => activeType === type ) ,
87+ ( ) => security ? .find ( ( { type} ) => activeType === type ) || undefined ,
8588 [ activeType ] ,
8689 ) ;
8790
@@ -90,9 +93,9 @@ function useEnhance({projectName, security}: SecurityProps) {
9093 } , [ setOpen ] ) ;
9194
9295 const open = useCallback ( ( ) => {
93- setActiveType ( auth . type || security [ 0 ] . type ) ;
96+ setActiveType ( auth . type || initialType ) ;
9497 setOpen ( true ) ;
95- } , [ setOpen ] ) ;
98+ } , [ setOpen , initialType ] ) ;
9699
97100 return {
98101 isOpen,
0 commit comments