@@ -17,6 +17,7 @@ import { useTypedSelector } from "@theme/ApiItem/hooks";
1717import { HTTPSnippet , TargetId } from "httpsnippet-lite" ;
1818import cloneDeep from "lodash/cloneDeep" ;
1919import * as sdk from "postman-collection" ;
20+ import type { Param } from "@theme/ApiExplorer/ParamOptions/slice" ;
2021
2122import { CodeSample , Language } from "./code-snippets-types" ;
2223import {
@@ -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