-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add OpenAPI UI into the server tab to enable local test from server to service --------- Co-authored-by: Liangying.Wei <[email protected]>
- Loading branch information
Showing
13 changed files
with
622 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
tools/awps-tunnel/client/src/components/api/EndpointNav.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { | ||
Accordion, | ||
AccordionHeader, | ||
AccordionItem, | ||
AccordionPanel, | ||
Label, | ||
Tab, | ||
TabList | ||
} from "@fluentui/react-components"; | ||
import React, { useEffect, useState } from "react"; | ||
import { PathItem } from "../../models"; | ||
import { methodColors } from './Methods'; | ||
import { useDataContext } from "../../providers/DataContext"; | ||
|
||
export function EndpointNav({ setSelectedPath }: { | ||
setSelectedPath: React.Dispatch<React.SetStateAction<string | undefined>> | ||
}): React.JSX.Element { | ||
const { data } = useDataContext(); | ||
const [categories, setCategories] = useState<{ | ||
general: { pathUrl: string, path: PathItem }[]; | ||
groups: { pathUrl: string, path: PathItem }[]; | ||
connections: { pathUrl: string, path: PathItem }[]; | ||
users: { pathUrl: string, path: PathItem }[]; | ||
permissions: { pathUrl: string, path: PathItem }[]; | ||
}>(); | ||
|
||
useEffect(() => { | ||
let categories: { | ||
general: { pathUrl: string, path: PathItem }[], | ||
groups: { pathUrl: string, path: PathItem }[], | ||
connections: { pathUrl: string, path: PathItem }[], | ||
users: { pathUrl: string, path: PathItem }[], | ||
permissions: { pathUrl: string, path: PathItem }[] | ||
} = { | ||
general: [], | ||
groups: [], | ||
connections: [], | ||
users: [], | ||
permissions: [] | ||
}; | ||
Object.entries(data.apiSpec.paths).forEach(([pathUrl, path]) => { | ||
const segments = pathUrl.split('/'); | ||
const category = segments[4] || 'general'; // Default to 'general' if no fourth segment | ||
switch (category) { | ||
case 'groups': | ||
categories.groups.push({ pathUrl: pathUrl, path: path as PathItem }); | ||
break; | ||
case 'connections': | ||
categories.connections.push({ pathUrl: pathUrl, path: path as PathItem }); | ||
break; | ||
case 'users': | ||
categories.users.push({ pathUrl: pathUrl, path: path as PathItem }); | ||
break; | ||
case 'permissions': | ||
categories.permissions.push({ pathUrl: pathUrl, path: path as PathItem }); | ||
break; | ||
default: | ||
categories.general.push({ pathUrl: pathUrl, path: path as PathItem }); | ||
break; | ||
} | ||
}); | ||
setCategories(categories); | ||
}, [data.apiSpec]); | ||
|
||
return (<div className="d-flex overflow-hidden" style={{ flex: 1 }}> | ||
<TabList onTabSelect={(_e, data) => { | ||
setSelectedPath(data.value as string) | ||
}} vertical> | ||
<Accordion multiple> | ||
{categories && Object.entries(categories).map(([category, path], index) => ( | ||
<AccordionItem key={index} value={category}> | ||
<AccordionHeader><Label size={"large"}>{category}</Label></AccordionHeader> | ||
<AccordionPanel> | ||
{Object.entries(path).map(([_url, { pathUrl, path }]) => ( | ||
Object.entries(path).map(([method, details]) => ( | ||
<Tab key={`${pathUrl}-${method}`} value={`${pathUrl}-${method}`}> | ||
<div className="d-flex"> | ||
<div | ||
className="fs-6 me-2" | ||
style={{ color: methodColors[method] }}>{method.toUpperCase()}</div> | ||
<div>{details.operationId.replace("WebPubSub_", "")}</div> | ||
</div> | ||
</Tab> | ||
)) | ||
))} | ||
</AccordionPanel> | ||
</AccordionItem> | ||
))} | ||
</Accordion> | ||
</TabList> | ||
</div>) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { Label } from "@fluentui/react-components"; | ||
import 'bootstrap/dist/css/bootstrap.min.css'; | ||
import React, { useEffect, useState } from "react"; | ||
import { APIResponse, Example, Operation } from "../../models"; | ||
import { Parameters } from "./Parameters"; | ||
import { Response } from "./Response"; | ||
|
||
export const methodColors: { [method: string]: string } = { | ||
post: "#ffd02b", | ||
put: "#4385d9", | ||
delete: "#f27263", | ||
head: "#a887c9" | ||
}; | ||
|
||
export function Method({ method, path, methodName }: { | ||
method: Operation, | ||
path: string, | ||
methodName: string | ||
}): React.JSX.Element { | ||
const [example, setExample] = useState<Example>(); | ||
const [response, setResponse] = useState<APIResponse | undefined>(undefined); | ||
useEffect(() => { | ||
if (method.operationId) { | ||
const operationId = method.operationId; | ||
const example = method["x-ms-examples"][operationId].$ref; | ||
fetch(`./api/${process.env.REACT_APP_API_VERSION}/${example}`).then(res => res.json()).then(res => setExample(res)) | ||
setResponse(undefined); | ||
} | ||
}, [method, path]); | ||
|
||
return ( | ||
<div className="d-flex"> | ||
<div className="p-3"> | ||
<Label className="fs-4 fw-bold ms-2">{method.summary}</Label> | ||
|
||
<div className="d-flex flex-row justify-content-start align-items-center ms-2"> | ||
<div className={"g-primary text-white rounded px-1 fs-6"} style={{ backgroundColor: methodColors[methodName] }}>{methodName.toUpperCase()} | ||
</div> | ||
<div className="mx-2">{path}</div> | ||
</div> | ||
|
||
|
||
{method.parameters && example && | ||
<Parameters path={path} parameters={method.parameters} example={example.parameters} | ||
setResponse={setResponse} methodName={methodName} />} | ||
<Response responseSchema={method.responses} response={response} /> | ||
</div> | ||
</div> | ||
) | ||
} |
Oops, something went wrong.