MCPcopy Create free account
hub / github.com/api-platform/website / SwaggerUI

Function SwaggerUI

pwa/app/playground/components/SwaggerUI.tsx:70–126  ·  view source on GitHub ↗
({
  guide,
  ccall,
}: {
  guide: string;
  ccall: any;
})

Source from the content-addressed store, hash-verified

68}
69
70export default function SwaggerUI({
71 guide,
72 ccall,
73}: {
74 guide: string;
75 ccall: any;
76}) {
77 const [openApiDoc, setOpenApiDoc] = useState(null);
78
79 useEffect(() => {
80 let ignore = false;
81
82 (async () => {
83 await Promise.resolve();
84 if (ignore) {
85 return;
86 }
87
88 ccall("setenv", null, [STR, STR, "number"], ["APP_GUIDE", guide, 1]);
89 const response = phpFetch(new URL("https://localhost/docs"), {
90 ccall,
91 });
92 const docs = await response.json();
93 setOpenApiDoc(docs);
94 })();
95
96 // @see https://marmelab.com/blog/2023/01/11/use-async-effect-react.html
97 return () => {
98 ignore = true;
99 };
100 }, [ccall, guide]);
101
102 // req is a swagger request with some special options
103 const requestInterceptor = useCallback(
104 (req: any) => {
105 req.userFetch = (url: string, opts: RequestInit) => {
106 return phpFetch(new URL(url), { ...opts, ccall });
107 };
108 return req;
109 },
110 [ccall]
111 );
112
113 if (!openApiDoc) {
114 return <div>Loading</div>;
115 }
116
117 return (
118 <SwaggerUIReact
119 docExpansion={"full"}
120 tryItOutEnabled={true}
121 requestInterceptor={requestInterceptor}
122 spec={openApiDoc}
123 syntaxHighlight={false} // react-syntax-highlighter is broken
124 />
125 );
126}

Callers

nothing calls this directly

Calls 1

phpFetchFunction · 0.85

Tested by

no test coverage detected