From 6d1ed20925604c9081fe796d496361d6d928a381 Mon Sep 17 00:00:00 2001
From: Steven Serrata <9343811+sserrata@users.noreply.github.com>
Date: Fri, 27 Jun 2025 13:14:54 -0500
Subject: [PATCH] chore: add typings and remove placeholders
---
.../src/openapi/openapi.ts | 4 ++--
.../src/postman-collection.d.ts | 10 ---------
.../src/types.ts | 2 +-
.../package.json | 2 ++
.../src/theme-translations.d.ts | 9 --------
.../theme/ApiExplorer/CodeSnippets/index.tsx | 6 +++---
.../src/theme/ApiExplorer/Request/index.tsx | 4 ++--
.../theme/ApiExplorer/Request/makeRequest.ts | 7 ++++---
.../theme/ApiExplorer/buildPostmanRequest.ts | 21 +++++++++++++------
.../src/theme/ApiExplorer/index.tsx | 6 ++++--
.../theme/ApiExplorer/postman-collection.d.ts | 10 ---------
.../src/theme/ApiExplorer/react-modal.d.ts | 8 -------
yarn.lock | 14 +++++++++++++
13 files changed, 47 insertions(+), 56 deletions(-)
delete mode 100644 packages/docusaurus-plugin-openapi-docs/src/postman-collection.d.ts
delete mode 100644 packages/docusaurus-theme-openapi-docs/src/theme-translations.d.ts
delete mode 100644 packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/postman-collection.d.ts
delete mode 100644 packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/react-modal.d.ts
diff --git a/packages/docusaurus-plugin-openapi-docs/src/openapi/openapi.ts b/packages/docusaurus-plugin-openapi-docs/src/openapi/openapi.ts
index 675c0a83f..503133feb 100644
--- a/packages/docusaurus-plugin-openapi-docs/src/openapi/openapi.ts
+++ b/packages/docusaurus-plugin-openapi-docs/src/openapi/openapi.ts
@@ -15,8 +15,8 @@ import kebabCase from "lodash/kebabCase";
import unionBy from "lodash/unionBy";
import uniq from "lodash/uniq";
import Converter from "openapi-to-postmanv2";
-import Collection from "postman-collection";
-import sdk from "postman-collection";
+import { Collection } from "postman-collection";
+import * as sdk from "postman-collection";
import { sampleRequestFromSchema } from "./createRequestExample";
import { OpenApiObject, TagGroupObject, TagObject } from "./types";
diff --git a/packages/docusaurus-plugin-openapi-docs/src/postman-collection.d.ts b/packages/docusaurus-plugin-openapi-docs/src/postman-collection.d.ts
deleted file mode 100644
index 1e002ccd4..000000000
--- a/packages/docusaurus-plugin-openapi-docs/src/postman-collection.d.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-/* ============================================================================
- * Copyright (c) Palo Alto Networks
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- * ========================================================================== */
-
-declare module "postman-collection" {
- export default any;
-}
diff --git a/packages/docusaurus-plugin-openapi-docs/src/types.ts b/packages/docusaurus-plugin-openapi-docs/src/types.ts
index 664728f99..eec717e5c 100644
--- a/packages/docusaurus-plugin-openapi-docs/src/types.ts
+++ b/packages/docusaurus-plugin-openapi-docs/src/types.ts
@@ -6,7 +6,7 @@
* ========================================================================== */
import { SidebarItemDoc } from "@docusaurus/plugin-content-docs/src/sidebars/types";
-import type Request from "postman-collection";
+import Request from "postman-collection";
import {
InfoObject,
diff --git a/packages/docusaurus-theme-openapi-docs/package.json b/packages/docusaurus-theme-openapi-docs/package.json
index 68172e1fb..caefb3dfc 100644
--- a/packages/docusaurus-theme-openapi-docs/package.json
+++ b/packages/docusaurus-theme-openapi-docs/package.json
@@ -35,6 +35,8 @@
"@types/file-saver": "^2.0.5",
"@types/lodash": "^4.14.176",
"@types/pako": "^2.0.3",
+ "@types/postman-collection": "^3.5.11",
+ "@types/react-modal": "^3.16.3",
"concurrently": "^5.2.0",
"docusaurus-plugin-openapi-docs": "^4.4.0",
"docusaurus-plugin-sass": "^0.2.3",
diff --git a/packages/docusaurus-theme-openapi-docs/src/theme-translations.d.ts b/packages/docusaurus-theme-openapi-docs/src/theme-translations.d.ts
deleted file mode 100644
index 03cc2e3b5..000000000
--- a/packages/docusaurus-theme-openapi-docs/src/theme-translations.d.ts
+++ /dev/null
@@ -1,9 +0,0 @@
-/* ============================================================================
- * Copyright (c) Palo Alto Networks
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- * ========================================================================== */
-
-// TODO: Remove this when https://github.com/facebook/docusaurus/issues/6087 is resolved.
-declare module "@docusaurus/theme-translations";
diff --git a/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/CodeSnippets/index.tsx b/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/CodeSnippets/index.tsx
index 914487d0c..ff830d8f3 100644
--- a/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/CodeSnippets/index.tsx
+++ b/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/CodeSnippets/index.tsx
@@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
* ========================================================================== */
-import React, { useState, useEffect, type JSX } from "react";
+import React, { useState, useEffect } from "react";
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
import ApiCodeBlock from "@theme/ApiExplorer/ApiCodeBlock";
@@ -14,7 +14,7 @@ import CodeTabs from "@theme/ApiExplorer/CodeTabs";
import { useTypedSelector } from "@theme/ApiItem/hooks";
import cloneDeep from "lodash/cloneDeep";
import codegen from "postman-code-generators";
-import sdk from "postman-collection";
+import * as sdk from "postman-collection";
import { CodeSample, Language } from "./code-snippets-types";
import {
@@ -31,7 +31,7 @@ export interface Props {
codeSamples: CodeSample[];
}
-function CodeTab({ children, hidden, className }: any): JSX.Element {
+function CodeTab({ children, hidden, className }: any): React.JSX.Element {
return (
{children}
diff --git a/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/Request/index.tsx b/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/Request/index.tsx
index e68b9f1df..30f7bcc69 100644
--- a/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/Request/index.tsx
+++ b/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/Request/index.tsx
@@ -26,7 +26,7 @@ import Server from "@theme/ApiExplorer/Server";
import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks";
import { ParameterObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
import { ApiItem } from "docusaurus-plugin-openapi-docs/src/types";
-import sdk from "postman-collection";
+import * as sdk from "postman-collection";
import { FormProvider, useForm } from "react-hook-form";
import makeRequest from "./makeRequest";
@@ -126,7 +126,7 @@ function Request({ item }: { item: ApiItem }) {
} else {
await handleResponse(res);
}
- } catch (e: any) {
+ } catch (e) {
console.log(e);
dispatch(setResponse("Connection failed"));
dispatch(clearCode());
diff --git a/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/Request/makeRequest.ts b/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/Request/makeRequest.ts
index d3014243f..6c335709b 100644
--- a/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/Request/makeRequest.ts
+++ b/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/Request/makeRequest.ts
@@ -6,7 +6,7 @@
* ========================================================================== */
import { Body } from "@theme/ApiExplorer/Body/slice";
-import sdk from "postman-collection";
+import * as sdk from "postman-collection";
function fetchWithtimeout(
url: string,
@@ -156,8 +156,9 @@ async function makeRequest(
myHeaders.delete("Content-Type");
myBody = new FormData();
- if (Array.isArray(request.body.formdata.members)) {
- for (const data of request.body.formdata.members) {
+ const members = (request.body as any)?.formdata?.members;
+ if (Array.isArray(members)) {
+ for (const data of members) {
if (data.key && data.value.content) {
myBody.append(data.key, data.value.content);
}
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 53af07e36..b3f884ae4 100644
--- a/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/buildPostmanRequest.ts
+++ b/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/buildPostmanRequest.ts
@@ -12,7 +12,7 @@ import {
ServerObject,
} from "docusaurus-plugin-openapi-docs/src/openapi/types";
import cloneDeep from "lodash/cloneDeep";
-import sdk from "postman-collection";
+import * as sdk from "postman-collection";
type Param = {
value?: string | string[];
@@ -73,7 +73,7 @@ function setQueryParams(postman: sdk.Request, queryParams: Param[]) {
([key, val]) =>
new sdk.QueryParam({
key: `${param.name}[${key}]`,
- value: val,
+ value: String(val),
})
);
} else if (param.explode) {
@@ -81,7 +81,7 @@ function setQueryParams(postman: sdk.Request, queryParams: Param[]) {
([key, val]) =>
new sdk.QueryParam({
key: key,
- value: val,
+ value: String(val),
})
);
} else {
@@ -181,7 +181,10 @@ function setPathParams(postman: sdk.Request, pathParams: Param[]) {
});
});
- postman.url.variables.assimilate(source, false);
+ postman.url.variables.assimilate(
+ source.filter((v): v is sdk.Variable => v !== undefined),
+ false
+ );
}
function buildCookie(cookieParams: Param[]) {
@@ -207,7 +210,9 @@ function buildCookie(cookieParams: Param[]) {
([key, val]) =>
new sdk.Cookie({
key: key,
- value: val,
+ value: String(val),
+ domain: "",
+ path: "",
})
);
} else {
@@ -217,6 +222,8 @@ function buildCookie(cookieParams: Param[]) {
value: Object.entries(jsonResult)
.map(([key, val]) => `${key},${val}`)
.join(","),
+ domain: "",
+ path: "",
});
}
}
@@ -224,7 +231,9 @@ function buildCookie(cookieParams: Param[]) {
// Handle scalar values
return new sdk.Cookie({
key: param.name,
- value: param.value,
+ value: String(param.value),
+ domain: "",
+ path: "",
});
}
}
diff --git a/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/index.tsx b/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/index.tsx
index 1272effd7..ddafa424f 100644
--- a/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/index.tsx
+++ b/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/index.tsx
@@ -12,7 +12,7 @@ import Request from "@theme/ApiExplorer/Request";
import Response from "@theme/ApiExplorer/Response";
import SecuritySchemes from "@theme/ApiExplorer/SecuritySchemes";
import { ApiItem } from "docusaurus-plugin-openapi-docs/src/types";
-import sdk from "postman-collection";
+import * as sdk from "postman-collection";
function ApiExplorer({
item,
@@ -21,7 +21,9 @@ function ApiExplorer({
item: NonNullable
;
infoPath: string;
}) {
- const postman = new sdk.Request(item.postman);
+ const postman = new sdk.Request(
+ item.postman ? (item.postman as any).toJSON() : {}
+ );
return (
<>
diff --git a/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/postman-collection.d.ts b/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/postman-collection.d.ts
deleted file mode 100644
index 5f614e48e..000000000
--- a/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/postman-collection.d.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-/* ============================================================================
- * Copyright (c) Palo Alto Networks
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- * ========================================================================== */
-
-declare module "postman-collection" {
- export = Request.sdk;
-}
diff --git a/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/react-modal.d.ts b/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/react-modal.d.ts
deleted file mode 100644
index 88e509e0f..000000000
--- a/packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/react-modal.d.ts
+++ /dev/null
@@ -1,8 +0,0 @@
-/* ============================================================================
- * Copyright (c) Palo Alto Networks
- *
- * This source code is licensed under the MIT license found in the
- * LICENSE file in the root directory of this source tree.
- * ========================================================================== */
-
-declare module "react-modal";
diff --git a/yarn.lock b/yarn.lock
index bec5444bc..dff1582fd 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -4294,6 +4294,13 @@
resolved "https://registry.yarnpkg.com/@types/parse5/-/parse5-6.0.3.tgz#705bb349e789efa06f43f128cef51240753424cb"
integrity sha512-SuT16Q1K51EAVPz1K29DJ/sXjhSQ0zjvsypYJ6tlwVsRV9jwW5Adq2ch8Dq8kDBCkYnELS7N7VNCSB5nC56t/g==
+"@types/postman-collection@^3.5.11":
+ version "3.5.11"
+ resolved "https://registry.yarnpkg.com/@types/postman-collection/-/postman-collection-3.5.11.tgz#384ca38d5635d5ec1d999d70c84c3c8226a47192"
+ integrity sha512-BZgBJDdX6jyy9hzSTIMRhCsxhF0IlzPr1i98q2wdkDo8rZrbNoBvs+3/Vw+LOIIAFH1G+FyXo5Fjf8qbawGeHg==
+ dependencies:
+ "@types/node" "*"
+
"@types/prettier@^2.1.5":
version "2.7.3"
resolved "https://registry.yarnpkg.com/@types/prettier/-/prettier-2.7.3.tgz#3e51a17e291d01d17d3fc61422015a933af7a08f"
@@ -4319,6 +4326,13 @@
resolved "https://registry.yarnpkg.com/@types/range-parser/-/range-parser-1.2.7.tgz#50ae4353eaaddc04044279812f52c8c65857dbcb"
integrity sha512-hKormJbkJqzQGhziax5PItDUTMAM9uE2XXQmM37dyd4hVM+5aVl7oVxMVUiVQn2oCQFN/LKCZdvSM0pFRqbSmQ==
+"@types/react-modal@^3.16.3":
+ version "3.16.3"
+ resolved "https://registry.yarnpkg.com/@types/react-modal/-/react-modal-3.16.3.tgz#250f32c07f1de28e2bcf9c3e84b56adaa6897013"
+ integrity sha512-xXuGavyEGaFQDgBv4UVm8/ZsG+qxeQ7f77yNrW3n+1J6XAstUy5rYHeIHPh1KzsGc6IkCIdu6lQ2xWzu1jBTLg==
+ dependencies:
+ "@types/react" "*"
+
"@types/react-redux@^7.1.20":
version "7.1.34"
resolved "https://registry.yarnpkg.com/@types/react-redux/-/react-redux-7.1.34.tgz#83613e1957c481521e6776beeac4fd506d11bd0e"