All files / src/development SwaggerApp.tsx

20% Statements 2/10
0% Branches 0/4
0% Functions 0/3
22.22% Lines 2/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37                      7x   7x                                              
import React, {ReactElement, Suspense} from 'react';
import "swagger-ui-react/swagger-ui.css";
import { SERVER_URL } from '@config/base';
import { getAccessToken } from '@utils/TokenUtils';
import './SwaggerApp.css';
 
interface Request {
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  [k: string]: any;
}
 
const SwaggerUI = React.lazy(() => import('swagger-ui-react'));
 
const SwaggerApp = (): ReactElement => (
  <div className="swagger-container">
    <Suspense fallback={<div></div>}>
      <SwaggerUI
    docExpansion="none"
    deepLinking={false}
    url={`${SERVER_URL}/swagger/api`}
    requestInterceptor={(request: Request): Request => {
      //Support with context-path added by nginx reverse proxy
      if (!request.url.endsWith('/swagger/api')) {
        request.url = `${SERVER_URL}${new URL(request.url).pathname}`;
      }
      const token = getAccessToken();
      if (token != null) {
        request.headers.Authorization = `Bearer ${token}`;
      }
      return request;
    }}
    />
    </Suspense>
  </div>
);
export default SwaggerApp;