Skip to content

Commit b0d2b7d

Browse files
authored
refactor: use docusaurus sidebar types (PaloAltoNetworks#1220)
* refactor: use docusaurus sidebar types * fix: resolve theme type conflicts * fix: resolve api explorer type errors
1 parent caa9e96 commit b0d2b7d

File tree

18 files changed

+57
-349
lines changed

18 files changed

+57
-349
lines changed

packages/docusaurus-plugin-openapi-docs/src/plugin-content-docs-types.d.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

packages/docusaurus-plugin-openapi-docs/src/plugin-openapi.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type { FrontMatter as DocsFrontMatter } from "@docusaurus/types";
1111
import type { Props as DocsProps } from "@docusaurus/types";
1212

1313
declare module "docusaurus-plugin-openapi-docs" {
14-
import type { PropSidebars } from "@docusaurus/plugin-content-docs-types";
14+
import type { PropSidebars } from "@docusaurus/plugin-content-docs/lib/sidebars/types";
1515

1616
export type Options = Partial<import("./types").APIOptions>;
1717

packages/docusaurus-plugin-openapi-docs/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* LICENSE file in the root directory of this source tree.
66
* ========================================================================== */
77

8-
import { SidebarItemDoc } from "@docusaurus/plugin-content-docs/src/sidebars/types";
8+
import type { SidebarItemDoc } from "@docusaurus/plugin-content-docs/lib/sidebars/types";
99
import Request from "postman-collection";
1010

1111
import {
@@ -21,7 +21,7 @@ export type {
2121
SidebarItemLink,
2222
PropSidebar,
2323
PropSidebarItem,
24-
} from "@docusaurus/plugin-content-docs-types";
24+
} from "@docusaurus/plugin-content-docs/lib/sidebars/types";
2525
export interface PluginOptions {
2626
id?: string;
2727
docsPlugin?: string;

packages/docusaurus-theme-openapi-docs/src/theme-openapi.d.ts

Lines changed: 7 additions & 275 deletions
Original file line numberDiff line numberDiff line change
@@ -7,282 +7,14 @@
77

88
/// <reference types="docusaurus-plugin-openapi-docs" />
99

10-
/* eslint-disable @typescript-eslint/no-use-before-define */
11-
12-
declare module "@docusaurus/plugin-content-docs-types" {
13-
// Makes all properties visible when hovering over the type
14-
type Expand<T extends Record<string, unknown>> = { [P in keyof T]: T[P] };
15-
16-
export type SidebarItemBase = {
17-
className?: string;
18-
customProps?: Record<string, unknown>;
19-
};
20-
21-
export type SidebarItemLink = SidebarItemBase & {
22-
type: "link";
23-
href: string;
24-
label: string;
25-
docId: string;
26-
};
27-
28-
type SidebarItemCategoryBase = SidebarItemBase & {
29-
type: "category";
30-
label: string;
31-
collapsed: boolean;
32-
collapsible: boolean;
33-
};
34-
35-
export type PropSidebarItemCategory = Expand<
36-
SidebarItemCategoryBase & {
37-
items: PropSidebarItem[];
38-
}
39-
>;
40-
41-
export type PropSidebarItem = SidebarItemLink | PropSidebarItemCategory;
42-
export type PropSidebar = PropSidebarItem[];
43-
export type PropSidebars = {
44-
[sidebarId: string]: PropSidebar;
45-
};
46-
}
10+
export type {
11+
PropSidebarItemCategory,
12+
SidebarItemLink,
13+
PropSidebar,
14+
PropSidebarItem,
15+
PropSidebars,
16+
} from "@docusaurus/plugin-content-docs/lib/sidebars/types";
4717

4818
declare module "docusaurus-theme-openapi-docs" {
4919
export type ThemeConfig = Partial<import("./types").ThemeConfig>;
5020
}
51-
52-
declare module "@theme/ApiItem/hooks" {
53-
export { useTypedDispatch, useTypedSelector };
54-
}
55-
56-
declare module "@theme/ApiItem/Layout" {
57-
export interface Props {
58-
readonly children: JSX.Element;
59-
}
60-
61-
export default function Layout(props: any): JSX.Element;
62-
}
63-
64-
declare module "@theme/ApiItem/store" {
65-
export { AppDispatch, RootState };
66-
}
67-
68-
declare module "@theme/SchemaTabs" {
69-
export default function SchemaTabs(props: any): JSX.Element;
70-
}
71-
72-
declare module "@theme/Markdown" {
73-
export default function Markdown(props: any): JSX.Element;
74-
}
75-
76-
declare module "@theme/ApiExplorer/Accept" {
77-
export default function Accept(): JSX.Element;
78-
}
79-
80-
declare module "@theme/ApiExplorer/Accept/slice" {
81-
export { setAccept };
82-
export default accept as Reducer<State, AnyAction>;
83-
}
84-
85-
declare module "@theme/ApiExplorer/Authorization" {
86-
export default function Authorization(): JSX.Element;
87-
}
88-
89-
declare module "@theme/ApiExplorer/Authorization/slice" {
90-
export { AuthState, Scheme, setAuthData, setSelectedAuth, createAuth };
91-
export default auth as Reducer<State, AnyAction>;
92-
}
93-
94-
declare module "@theme/ApiExplorer/Body" {
95-
import { Props as BodyProps } from "@theme/ApiExplorer/Body";
96-
97-
export default function Body(props: BodyProps): JSX.Element;
98-
}
99-
100-
declare module "@theme/ApiExplorer/Body/json2xml" {
101-
export default function json2xml(any, any?): any;
102-
}
103-
104-
declare module "@theme/ApiExplorer/Body/slice" {
105-
import { Body, Content, State } from "@theme/ApiExplorer/Body/slice";
106-
107-
export { Body, Content, State };
108-
export function setStringRawBody(any, any?): any;
109-
export default body as Reducer<State, AnyAction>;
110-
}
111-
112-
declare module "@theme/ApiExplorer/buildPostmanRequest" {
113-
export default function buildPostmanRequest(any, any?): any;
114-
}
115-
116-
declare module "@theme/ApiExplorer/CodeTabs" {
117-
import { Props as CodeTabsProps } from "@theme/ApiExplorer/CodeTabs";
118-
119-
export default function CodeTabs(props: CodeTabsProps): JSX.Element;
120-
}
121-
122-
declare module "@theme/ApiExplorer/ContentType" {
123-
export default function ContentType(): JSX.Element;
124-
}
125-
126-
declare module "@theme/ApiExplorer/ContentType/slice" {
127-
export { setContentType };
128-
export default contentType as Reducer<State, AnyAction>;
129-
}
130-
131-
declare module "@theme/ApiExplorer/CodeSnippets" {
132-
import { Props as CurlProps } from "@theme/ApiExplorer/CodeSnippets";
133-
134-
export { languageSet, Language } from "@theme/ApiExplorer/CodeSnippets";
135-
export default function Curl(props: CurlProps): JSX.Element;
136-
}
137-
138-
declare module "@theme/ApiExplorer/FloatingButton" {
139-
import { Props as FloatingButtonProps } from "@theme/ApiExplorer/FloatingButton";
140-
141-
export default function FloatingButton(
142-
props: FloatingButtonProps
143-
): JSX.Element;
144-
}
145-
146-
declare module "@theme/ApiExplorer/FormItem" {
147-
import { Props as FormItemProps } from "@theme/ApiExplorer/FormItem";
148-
149-
export default function FormItem(props: FormItemProps): JSX.Element;
150-
}
151-
152-
declare module "@theme/ApiExplorer/FormSelect" {
153-
import { Props as FormSelectProps } from "@theme/ApiExplorer/FormSelect";
154-
155-
export default function FormSelect(props: FormSelectProps): JSX.Element;
156-
}
157-
158-
declare module "@theme/ApiExplorer/FormTextInput" {
159-
import { Props as FormTextInputProps } from "@theme/ApiExplorer/FormTextInput";
160-
161-
export default function FormTextInput(props: FormTextInputProps): JSX.Element;
162-
}
163-
164-
declare module "@theme/ApiExplorer/FormFileUpload" {
165-
import { Props as FormFileUploadProps } from "@theme/ApiExplorer/FormFileUpload";
166-
167-
export default function FormFileUpload(
168-
props: FormFileUploadProps
169-
): JSX.Element;
170-
}
171-
172-
declare module "@theme/ApiExplorer/FormMultiSelect" {
173-
import { Props as FormMultiSelectProps } from "@theme/ApiExplorer/FormMultiSelect";
174-
175-
export default function FormMultiSelect(
176-
props: FormMultiSelectProps
177-
): JSX.Element;
178-
}
179-
180-
declare module "@theme/ApiExplorer/Execute" {
181-
import { Props as ExecuteProps } from "@theme/ApiExplorer/Execute";
182-
183-
export default function Execute(props: ExecuteProps): JSX.Element;
184-
}
185-
186-
declare module "@theme/ApiExplorer/LiveEditor" {
187-
export default function LiveEditor(props: any): JSX.Element;
188-
}
189-
190-
declare module "@theme/ApiExplorer/MethodEndpoint" {
191-
import { Props as MethodEndpointProps } from "@theme/ApiExplorer/MethodEndpoint";
192-
193-
export default function MethodEndpoint(
194-
props: MethodEndpointProps
195-
): JSX.Element;
196-
}
197-
198-
declare module "@theme/ApiExplorer/ParamOptions" {
199-
import { ParamProps } from "@theme/ApiExplorer/ParamOptions";
200-
201-
export default function ParamOptions(props: ParamProps): JSX.Element;
202-
}
203-
204-
declare module "@theme/ApiExplorer/ParamOptions/ParamFormItems/ParamMultiSelectFormItem" {
205-
import { ParamProps } from "@theme/ApiExplorer/ParamOptions";
206-
207-
export default function ParamMultiSelectFormItem(
208-
props: ParamProps
209-
): JSX.Element;
210-
}
211-
212-
declare module "@theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem" {
213-
import { ParamProps } from "@theme/ApiExplorer/ParamOptions";
214-
215-
export default function ParamArrayFormItem(props: ParamProps): JSX.Element;
216-
}
217-
218-
declare module "@theme/ApiExplorer/ParamOptions/ParamFormItems/ParamSelectFormItem" {
219-
import { ParamProps } from "@theme/ApiExplorer/ParamOptions";
220-
221-
export default function ParamSelectFormItem(props: ParamProps): JSX.Element;
222-
}
223-
224-
declare module "@theme/ApiExplorer/ParamOptions/ParamFormItems/ParamBooleanFormItem" {
225-
import { ParamProps } from "@theme/ApiExplorer/ParamOptions";
226-
227-
export default function ParamBooleanFormItem(props: ParamProps): JSX.Element;
228-
}
229-
230-
declare module "@theme/ApiExplorer/ParamOptions/ParamFormItems/ParamTextFormItem" {
231-
import { ParamProps } from "@theme/ApiExplorer/ParamOptions";
232-
233-
export default function ParamTextFormItem(props: ParamProps): JSX.Element;
234-
}
235-
236-
declare module "@theme/ApiExplorer/ParamOptions/slice" {
237-
export type { Param };
238-
export const setParam;
239-
export default params as Reducer<State, AnyAction>;
240-
}
241-
242-
declare module "@theme/ApiExplorer/persistanceMiddleware" {
243-
export { createPersistanceMiddleware };
244-
}
245-
246-
declare module "@theme/ApiExplorer/Request" {
247-
import { ApiItem } from "docusaurus-plugin-openapi-docs/src/types";
248-
249-
export interface RequestProps {
250-
item: NonNullable<ApiItem>;
251-
}
252-
export default function Request(props: RequestProps): JSX.Element;
253-
}
254-
255-
declare module "@theme/ApiExplorer/Response" {
256-
import { ApiItem } from "docusaurus-plugin-openapi-docs/src/types";
257-
258-
export interface ResponseProps {
259-
item: NonNullable<ApiItem>;
260-
}
261-
262-
export default function Response(props: ResponseProps): JSX.Element;
263-
}
264-
265-
declare module "@theme/ApiExplorer/Response/slice" {
266-
export { setResponse, setCode, setHeaders, clearCode, clearHeaders };
267-
export default response as Reducer<State, AnyAction>;
268-
}
269-
270-
declare module "@theme/ApiExplorer/SecuritySchemes" {
271-
export default function SecuritySchemes(props: any): JSX.Element;
272-
}
273-
274-
declare module "@theme/ApiExplorer/Server" {
275-
export default function Server(): JSX.Element;
276-
}
277-
278-
declare module "@theme/ApiExplorer/ApiCodeBlock" {
279-
export default function ApiCodeBlock(): JSX.Element;
280-
}
281-
282-
declare module "@theme/ApiExplorer/Server/slice" {
283-
export default server as Reducer<State, AnyAction>;
284-
}
285-
286-
declare module "@theme/ApiExplorer/storage-utils" {
287-
export { createStorage, hashArray };
288-
}

packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/Authorization/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function Authorization() {
4343
<FormSelect
4444
options={optionKeys}
4545
value={selected}
46-
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
46+
onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {
4747
dispatch(setSelectedAuth(e.target.value));
4848
}}
4949
/>

packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/Body/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ function Body({
174174
>
175175
<FormSelect
176176
options={["---", ...val.enum]}
177-
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
177+
onChange={(e: React.ChangeEvent<HTMLSelectElement>) => {
178178
const val = e.target.value;
179179
if (val === "---") {
180180
dispatch(clearFormBodyKey(key));
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/* ============================================================================
2+
* Copyright (c) Palo Alto Networks
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
* ========================================================================== */
7+
8+
export default function json2xml(input: any, indent?: any): any;

0 commit comments

Comments
 (0)