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

Function queryParamEntries

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

Source from the content-addressed store, hash-verified

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

Callers 1

invoke.tsFile · 0.85

Calls 2

primitiveToStringFunction · 0.85
isRecordFunction · 0.70

Tested by

no test coverage detected