Skip to content

Commit 3981aa1

Browse files
committed
fix: supply default path param values for HAR
1 parent 24393e5 commit 3981aa1

File tree

1 file changed

+21
-7
lines changed
  • packages/docusaurus-theme-openapi-docs/src/theme/ApiExplorer/CodeSnippets

1 file changed

+21
-7
lines changed

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { useTypedSelector } from "@theme/ApiItem/hooks";
1717
import { HTTPSnippet, TargetId } from "httpsnippet-lite";
1818
import cloneDeep from "lodash/cloneDeep";
1919
import * as sdk from "postman-collection";
20+
import type { Param } from "@theme/ApiExplorer/ParamOptions/slice";
2021

2122
import { CodeSample, Language } from "./code-snippets-types";
2223
import {
@@ -195,13 +196,26 @@ function CodeSnippets({
195196
const collection = new sdk.Collection({
196197
item: [{ name: "request", request: cleanedPostmanRequest }],
197198
});
198-
const [harRequest] = await postman2har({
199-
...collection.toJSON(),
200-
info: {
201-
schema:
202-
"https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
203-
},
204-
} as Postman.Document);
199+
200+
const environment = Object.fromEntries(
201+
pathParams.map((param: Param) => [
202+
param.name,
203+
Array.isArray(param.value)
204+
? param.value[0]
205+
: (param.value ?? `<${param.name}>`),
206+
])
207+
);
208+
209+
const [harRequest] = await postman2har(
210+
{
211+
...collection.toJSON(),
212+
info: {
213+
schema:
214+
"https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
215+
},
216+
} as Postman.Document,
217+
{ environment }
218+
);
205219
const snippet = await new HTTPSnippet(harRequest).convert(
206220
mergedLanguage.language as TargetId,
207221
selectedVariant ?? mergedLanguage.variant,

0 commit comments

Comments
 (0)