Skip to content

Commit b251ee3

Browse files
authored
chore: add typings and remove placeholders (#1175)
1 parent a657d78 commit b251ee3

File tree

13 files changed

+47
-56
lines changed

13 files changed

+47
-56
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ import kebabCase from "lodash/kebabCase";
1515
import unionBy from "lodash/unionBy";
1616
import uniq from "lodash/uniq";
1717
import Converter from "openapi-to-postmanv2";
18-
import Collection from "postman-collection";
19-
import sdk from "postman-collection";
18+
import { Collection } from "postman-collection";
19+
import * as sdk from "postman-collection";
2020

2121
import { sampleRequestFromSchema } from "./createRequestExample";
2222
import { OpenApiObject, TagGroupObject, TagObject } from "./types";

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

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* ========================================================================== */
77

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

1111
import {
1212
InfoObject,

packages/docusaurus-theme-openapi-docs/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
"@types/file-saver": "^2.0.5",
3636
"@types/lodash": "^4.14.176",
3737
"@types/pako": "^2.0.3",
38+
"@types/postman-collection": "^3.5.11",
39+
"@types/react-modal": "^3.16.3",
3840
"concurrently": "^5.2.0",
3941
"docusaurus-plugin-openapi-docs": "^4.4.0",
4042
"docusaurus-plugin-sass": "^0.2.3",

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

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

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

Lines changed: 3 additions & 3 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 React, { useState, useEffect, type JSX } from "react";
8+
import React, { useState, useEffect } from "react";
99

1010
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
1111
import ApiCodeBlock from "@theme/ApiExplorer/ApiCodeBlock";
@@ -14,7 +14,7 @@ import CodeTabs from "@theme/ApiExplorer/CodeTabs";
1414
import { useTypedSelector } from "@theme/ApiItem/hooks";
1515
import cloneDeep from "lodash/cloneDeep";
1616
import codegen from "postman-code-generators";
17-
import sdk from "postman-collection";
17+
import * as sdk from "postman-collection";
1818

1919
import { CodeSample, Language } from "./code-snippets-types";
2020
import {
@@ -31,7 +31,7 @@ export interface Props {
3131
codeSamples: CodeSample[];
3232
}
3333

34-
function CodeTab({ children, hidden, className }: any): JSX.Element {
34+
function CodeTab({ children, hidden, className }: any): React.JSX.Element {
3535
return (
3636
<div role="tabpanel" className={className} {...{ hidden }}>
3737
{children}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import Server from "@theme/ApiExplorer/Server";
2626
import { useTypedDispatch, useTypedSelector } from "@theme/ApiItem/hooks";
2727
import { ParameterObject } from "docusaurus-plugin-openapi-docs/src/openapi/types";
2828
import { ApiItem } from "docusaurus-plugin-openapi-docs/src/types";
29-
import sdk from "postman-collection";
29+
import * as sdk from "postman-collection";
3030
import { FormProvider, useForm } from "react-hook-form";
3131

3232
import makeRequest from "./makeRequest";
@@ -126,7 +126,7 @@ function Request({ item }: { item: ApiItem }) {
126126
} else {
127127
await handleResponse(res);
128128
}
129-
} catch (e: any) {
129+
} catch (e) {
130130
console.log(e);
131131
dispatch(setResponse("Connection failed"));
132132
dispatch(clearCode());

packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/Request/makeRequest.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* ========================================================================== */
77

88
import { Body } from "@theme/ApiExplorer/Body/slice";
9-
import sdk from "postman-collection";
9+
import * as sdk from "postman-collection";
1010

1111
function fetchWithtimeout(
1212
url: string,
@@ -156,8 +156,9 @@ async function makeRequest(
156156
myHeaders.delete("Content-Type");
157157

158158
myBody = new FormData();
159-
if (Array.isArray(request.body.formdata.members)) {
160-
for (const data of request.body.formdata.members) {
159+
const members = (request.body as any)?.formdata?.members;
160+
if (Array.isArray(members)) {
161+
for (const data of members) {
161162
if (data.key && data.value.content) {
162163
myBody.append(data.key, data.value.content);
163164
}

packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/buildPostmanRequest.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import {
1212
ServerObject,
1313
} from "docusaurus-plugin-openapi-docs/src/openapi/types";
1414
import cloneDeep from "lodash/cloneDeep";
15-
import sdk from "postman-collection";
15+
import * as sdk from "postman-collection";
1616

1717
type Param = {
1818
value?: string | string[];
@@ -73,15 +73,15 @@ function setQueryParams(postman: sdk.Request, queryParams: Param[]) {
7373
([key, val]) =>
7474
new sdk.QueryParam({
7575
key: `${param.name}[${key}]`,
76-
value: val,
76+
value: String(val),
7777
})
7878
);
7979
} else if (param.explode) {
8080
return Object.entries(jsonResult).map(
8181
([key, val]) =>
8282
new sdk.QueryParam({
8383
key: key,
84-
value: val,
84+
value: String(val),
8585
})
8686
);
8787
} else {
@@ -181,7 +181,10 @@ function setPathParams(postman: sdk.Request, pathParams: Param[]) {
181181
});
182182
});
183183

184-
postman.url.variables.assimilate(source, false);
184+
postman.url.variables.assimilate(
185+
source.filter((v): v is sdk.Variable => v !== undefined),
186+
false
187+
);
185188
}
186189

187190
function buildCookie(cookieParams: Param[]) {
@@ -207,7 +210,9 @@ function buildCookie(cookieParams: Param[]) {
207210
([key, val]) =>
208211
new sdk.Cookie({
209212
key: key,
210-
value: val,
213+
value: String(val),
214+
domain: "",
215+
path: "",
211216
})
212217
);
213218
} else {
@@ -217,14 +222,18 @@ function buildCookie(cookieParams: Param[]) {
217222
value: Object.entries(jsonResult)
218223
.map(([key, val]) => `${key},${val}`)
219224
.join(","),
225+
domain: "",
226+
path: "",
220227
});
221228
}
222229
}
223230
} else {
224231
// Handle scalar values
225232
return new sdk.Cookie({
226233
key: param.name,
227-
value: param.value,
234+
value: String(param.value),
235+
domain: "",
236+
path: "",
228237
});
229238
}
230239
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Request from "@theme/ApiExplorer/Request";
1212
import Response from "@theme/ApiExplorer/Response";
1313
import SecuritySchemes from "@theme/ApiExplorer/SecuritySchemes";
1414
import { ApiItem } from "docusaurus-plugin-openapi-docs/src/types";
15-
import sdk from "postman-collection";
15+
import * as sdk from "postman-collection";
1616

1717
function ApiExplorer({
1818
item,
@@ -21,7 +21,9 @@ function ApiExplorer({
2121
item: NonNullable<ApiItem>;
2222
infoPath: string;
2323
}) {
24-
const postman = new sdk.Request(item.postman);
24+
const postman = new sdk.Request(
25+
item.postman ? (item.postman as any).toJSON() : {}
26+
);
2527

2628
return (
2729
<>

0 commit comments

Comments
 (0)