Adding requestInterceptor
Signed-off-by: Mauricio Martinez <mauricio.martinez@premise.com>
This commit is contained in:
@@ -38,8 +38,14 @@ paths:
|
||||
"200":
|
||||
description: Success
|
||||
`;
|
||||
|
||||
const requestInterceptor = (req: any) => req;
|
||||
|
||||
const { getByText } = await renderInTestApp(
|
||||
<OpenApiDefinition definition={definition} />,
|
||||
<OpenApiDefinition
|
||||
definition={definition}
|
||||
requestInterceptor={requestInterceptor}
|
||||
/>,
|
||||
);
|
||||
|
||||
// swagger-ui loads the documentation asynchronously
|
||||
|
||||
@@ -18,6 +18,7 @@ import { makeStyles } from '@material-ui/core/styles';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import SwaggerUI from 'swagger-ui-react';
|
||||
import 'swagger-ui-react/swagger-ui.css';
|
||||
import { Request } from './';
|
||||
|
||||
const useStyles = makeStyles(theme => ({
|
||||
root: {
|
||||
@@ -136,9 +137,13 @@ const useStyles = makeStyles(theme => ({
|
||||
|
||||
export type OpenApiDefinitionProps = {
|
||||
definition: string;
|
||||
requestInterceptor?: (req: Request) => Request | Promise<Request>;
|
||||
};
|
||||
|
||||
export const OpenApiDefinition = ({ definition }: OpenApiDefinitionProps) => {
|
||||
export const OpenApiDefinition = ({
|
||||
definition,
|
||||
requestInterceptor,
|
||||
}: OpenApiDefinitionProps) => {
|
||||
const classes = useStyles();
|
||||
|
||||
// Due to a bug in the swagger-ui-react component, the component needs
|
||||
@@ -152,7 +157,12 @@ export const OpenApiDefinition = ({ definition }: OpenApiDefinitionProps) => {
|
||||
|
||||
return (
|
||||
<div className={classes.root}>
|
||||
<SwaggerUI spec={def} url="" deepLinking />
|
||||
<SwaggerUI
|
||||
spec={def}
|
||||
url=""
|
||||
requestInterceptor={requestInterceptor}
|
||||
deepLinking
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
import { Progress } from '@backstage/core-components';
|
||||
import React, { Suspense } from 'react';
|
||||
import { Request } from './';
|
||||
|
||||
// The swagger-ui component and related CSS has a significant size, only load it
|
||||
// if the element is actually used.
|
||||
@@ -28,6 +29,7 @@ const LazyOpenApiDefinition = React.lazy(() =>
|
||||
/** @public */
|
||||
export type OpenApiDefinitionWidgetProps = {
|
||||
definition: string;
|
||||
requestInterceptor?: (req: Request) => Request | Promise<Request>;
|
||||
};
|
||||
|
||||
/** @public */
|
||||
|
||||
@@ -16,3 +16,7 @@
|
||||
|
||||
export { OpenApiDefinitionWidget } from './OpenApiDefinitionWidget';
|
||||
export type { OpenApiDefinitionWidgetProps } from './OpenApiDefinitionWidget';
|
||||
|
||||
export interface Request {
|
||||
[k: string]: any;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user