import React , { PropsWithChildren } from 'react' ; import './Swagger.scss' ; import SwaggerUI from "swagger-ui-react" ; import "swagger-ui-react/swagger-ui.css" ; import { getSpec } from './swaggerSpec' ; import { IProfileProps } from '../../models' ; export function Swagger ( props ) { const { profile } = props ; const generateSpec = ( profile ) => { return getSpec ( profile ) ; } ; const requestInterceptor = ( req ) => { const type = req . url . split ( '/' ) . reverse ( ) [ 0 ] ; req . url = `https://api.flickr.com/services/rest?format=json&t=${ type }` ; return req ; } ; const responseInterceptor = ( res ) => { const type = res . url . split ( '=' ) . reverse ( ) [ 0 ] ; res . body = res . text = res . data = res . obj = JSON . stringify ( profile [ type ] , null , 2 ) ; return res ; } ; return ( < > < div id = "swagger-wrapper" > < SwaggerUI spec = { generateSpec ( profile ) } docExpansion = "list" requestInterceptor = { requestInterceptor } responseInterceptor = { responseInterceptor } / > < /div> < />); }