MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / queryParamEntries

Function queryParamEntries

packages/plugins/openapi/src/sdk/invoke.ts:70–110  ·  view source on GitHub ↗
(value: unknown, param: OperationParameter)

Source from the content-addressed store, hash-verified

68 typeof value === "object" && value !== null && !Array.isArray(value);
69
70const queryParamEntries = (value: unknown, param: OperationParameter): QueryParamEntry[] => {
71 if (value === undefined || value === null) return [];
72
73 const style = Option.getOrUndefined(param.style) ?? "form";
74 const explode = Option.getOrElse(param.explode, () => true);
75
76 if (isRecord(value)) {
77 const entries = Object.entries(value).filter(
78 ([, nested]) => nested !== undefined && nested !== null,
79 );
80
81 if (style === "form") {
82 if (explode) {
83 // OAS form + explode=true serializes an object as top-level query
84 // fields, e.g. `{ region: "west", tier: "standard" }` ->
85 // `region=west&tier=standard`.
86 return entries.map(([name, nested]) => [name, primitiveToString(nested)]);
87 }
88
89 return [
90 [
91 param.name,
92 entries.flatMap(([name, nested]) => [name, primitiveToString(nested)]).join(","),
93 ],
94 ];
95 }
96
97 if (style === "deepObject") {
98 return entries.map(([name, nested]) => [`${param.name}[${name}]`, primitiveToString(nested)]);
99 }
100
101 return [[param.name, primitiveToString(value)]];
102 }
103
104 if (!Array.isArray(value)) return [[param.name, primitiveToString(value)]];
105
106 if (explode) return value.map((nested) => [param.name, primitiveToString(nested)]);
107
108 const separator = style === "spaceDelimited" ? " " : style === "pipeDelimited" ? "|" : ",";
109 return [[param.name, value.map(primitiveToString).join(separator)]];
110};
111
112// ---------------------------------------------------------------------------
113// Path resolution

Callers 1

invoke.tsFile · 0.85

Calls 2

primitiveToStringFunction · 0.85
isRecordFunction · 0.70

Tested by

no test coverage detected