From fa3fbbf0f66696f1a12600726ed6928670fcb14f Mon Sep 17 00:00:00 2001 From: Bryan Date: Thu, 30 Jan 2025 13:10:26 -0800 Subject: [PATCH 01/10] Add manual support for explode property --- .../src/theme/ApiExplorer/buildPostmanRequest.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/buildPostmanRequest.ts b/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/buildPostmanRequest.ts index c40e5d9e3..743d291d2 100644 --- a/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/buildPostmanRequest.ts +++ b/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/buildPostmanRequest.ts @@ -28,6 +28,17 @@ function setQueryParams(postman: sdk.Request, queryParams: Param[]) { } if (Array.isArray(param.value)) { + // Manual support for handling exploded query params + if (param.explode) { + let queryStringArr = []; + + for (let i = 0; i < param.value.length; i++) { + queryStringArr.push(`${param.name}=${param.value[i]}`); + } + + return queryStringArr.join("&"); + } + return new sdk.QueryParam({ key: param.name, value: param.value.join(","), From d786ecf8ea900e8386bd87702993b4d803c84084 Mon Sep 17 00:00:00 2001 From: Bryan Date: Thu, 30 Jan 2025 13:13:14 -0800 Subject: [PATCH 02/10] Add prefilled state for array param examples --- .../ParamFormItems/ParamArrayFormItem.tsx | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx b/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx index d28430f92..de7331724 100644 --- a/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx +++ b/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/ParamOptions/ParamFormItems/ParamArrayFormItem.tsx @@ -22,7 +22,10 @@ export interface ParamProps { function ArrayItem({ param, onChange, -}: ParamProps & { onChange(value?: string): any }) { + initialValue, +}: ParamProps & { onChange(value?: string): any; initialValue?: string }) { + const [value, setValue] = useState(initialValue || ""); + if (param.schema?.items?.type === "boolean") { return ( ) => { + setValue(e.target.value); onChange(e.target.value); }} /> @@ -76,9 +81,21 @@ export default function ParamArrayFormItem({ param }: ParamProps) { value: values.length > 0 ? values : undefined, }) ); + // eslint-disable-next-line react-hooks/exhaustive-deps }, [items]); + useEffect(() => { + if (param.schema?.example?.length > 0) { + const examplesWithIds = param.schema.example.map((item: any) => ({ + id: nanoid(), + value: item.toString(), + })); + + setItems(examplesWithIds); + } + }, [param.schema.example, param.schema.length]); + function handleDeleteItem(itemToDelete: { id: string }) { return () => { const newItems = items.filter((i) => i.id !== itemToDelete.id); @@ -112,6 +129,7 @@ export default function ParamArrayFormItem({ param }: ParamProps) {