55 * LICENSE file in the root directory of this source tree.
66 * ========================================================================== */
77
8- import zlib from "zlib" ;
9-
108import React from "react" ;
119
1210import BrowserOnly from "@docusaurus/BrowserOnly" ;
@@ -23,13 +21,16 @@ import type { Props } from "@theme/DocItem";
2321import DocItemMetadata from "@theme/DocItem/Metadata" ;
2422import SkeletonLoader from "@theme/SkeletonLoader" ;
2523import clsx from "clsx" ;
26- import { ServerObject } from "docusaurus-plugin-openapi-docs/src/openapi/types" ;
27- import { ParameterObject } from "docusaurus-plugin-openapi-docs/src/openapi/types" ;
24+ import {
25+ ParameterObject ,
26+ ServerObject ,
27+ } from "docusaurus-plugin-openapi-docs/src/openapi/types" ;
2828import type { ApiItem as ApiItemType } from "docusaurus-plugin-openapi-docs/src/types" ;
2929import type {
3030 DocFrontMatter ,
3131 ThemeConfig ,
3232} from "docusaurus-theme-openapi-docs/src/types" ;
33+ import { ungzip } from "pako" ;
3334import { Provider } from "react-redux" ;
3435
3536import { createStoreWithoutState , createStoreWithState } from "./store" ;
@@ -52,6 +53,16 @@ interface SampleFrontMatter extends DocFrontMatter {
5253 readonly sample ?: any ;
5354}
5455
56+ function base64ToUint8Array ( base64 : string ) {
57+ const binary = atob ( base64 ) ;
58+ const len = binary . length ;
59+ const bytes = new Uint8Array ( len ) ;
60+ for ( let i = 0 ; i < len ; i ++ ) {
61+ bytes [ i ] = binary . charCodeAt ( i ) ;
62+ }
63+ return bytes ;
64+ }
65+
5566// @ts -ignore
5667export default function ApiItem ( props : Props ) : JSX . Element {
5768 const docHtmlClassName = `docs-doc-id-${ props . content . metadata . id } ` ;
@@ -65,7 +76,7 @@ export default function ApiItem(props: Props): JSX.Element {
6576 if ( api ) {
6677 try {
6778 api = JSON . parse (
68- zlib . inflateSync ( Buffer . from ( api as any , "base64" ) as any ) . toString ( )
79+ new TextDecoder ( ) . decode ( ungzip ( base64ToUint8Array ( api as any ) ) )
6980 ) ;
7081 } catch { }
7182 }
0 commit comments