Skip to content

Commit 1796c33

Browse files
committed
feat: 🎸 optional query params generation
1 parent f0539e8 commit 1796c33

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

‎packages/cli/src/codegen/openapi/generator.ts‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,7 @@ export const createSdk = <Client extends ClientInstance>(client: Client, options
164164
? `${createTypeBaseName(id)}QueryParams`
165165
: undefined;
166166

167-
const QueryParamsGeneric =
168-
QueryParams && queryParamsRequired === false ? `${QueryParams} | undefined` : QueryParams;
167+
const QueryParamsGeneric = QueryParams && !queryParamsRequired ? `${QueryParams} | undefined` : QueryParams;
169168

170169
return `Request<${Response}, ${Payload}, ${QueryParamsGeneric}, ${LocalError}, "${endpoint}", Client>`;
171170
}
@@ -208,7 +207,7 @@ export const createSdk = <Client extends ClientInstance>(client: Client, options
208207
addToGenericType("error", LocalError);
209208
}
210209
if (QueryParams) {
211-
const key = queryParamsRequired === false ? "queryParams?" : "queryParams";
210+
const key = !queryParamsRequired ? "queryParams?" : "queryParams";
212211
addToGenericType(key, QueryParams);
213212
}
214213

@@ -289,13 +288,10 @@ export const createSdk = <Client extends ClientInstance>(client: Client, options
289288
const responseType = !lodash.isEmpty(responseTypePaths) ? responseTypePaths.join(" | ") : "any";
290289
const errorType = !lodash.isEmpty(errorTypePaths) ? errorTypePaths.join(" | ") : "undefined";
291290
const queryParamsRequired = Array.isArray(operation.parameters)
292-
? operation.parameters.every((p) => {
293-
if ("in" in p && p.in === "query" && p.required === false) {
294-
return true;
295-
}
296-
return false;
291+
? operation.parameters.some((p) => {
292+
return "in" in p && p.in === "query" && p.required === true;
297293
})
298-
: undefined;
294+
: false;
299295

300296
return {
301297
id: normalizedOperationId,

0 commit comments

Comments
 (0)