Merge pull request #19260 from nthings/master

Adding requestInterceptor option to `api-docs` plugin and pass it to SwaggerUI
This commit is contained in:
Patrik Oldsberg
2023-09-26 13:43:58 +02:00
committed by GitHub
6 changed files with 64 additions and 3 deletions
@@ -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
@@ -136,9 +136,13 @@ const useStyles = makeStyles(theme => ({
export type OpenApiDefinitionProps = {
definition: string;
requestInterceptor?: (req: any) => any | Promise<any>;
};
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 +156,12 @@ export const OpenApiDefinition = ({ definition }: OpenApiDefinitionProps) => {
return (
<div className={classes.root}>
<SwaggerUI spec={def} url="" deepLinking />
<SwaggerUI
spec={def}
url=""
requestInterceptor={requestInterceptor}
deepLinking
/>
</div>
);
};
@@ -28,6 +28,7 @@ const LazyOpenApiDefinition = React.lazy(() =>
/** @public */
export type OpenApiDefinitionWidgetProps = {
definition: string;
requestInterceptor?: (req: any) => any | Promise<any>;
};
/** @public */