Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor makeRequestsPropertyAssignment to use loop over HTTP methods #46

Merged
merged 8 commits into from
Jan 1, 2024
53 changes: 18 additions & 35 deletions src/common/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ import {

import type { CLIOptions } from "../cli";

const methods = [
"get",
"delete",
"post",
"put",
"patch",
"head",
"options",
] as const;

export function makeRequests(
$refs: SwaggerParser.$Refs,
paths: OpenAPIV3.PathsObject,
Expand Down Expand Up @@ -142,41 +152,14 @@ function makeRequestsPropertyAssignment(
const requests: ts.PropertyAssignment[] = [];
const params = item.parameters;

if (item.get) {
requests.push(
makeRequest($refs, pattern, "get", item.get, options, params)
);
}
if (item.delete) {
requests.push(
makeRequest($refs, pattern, "delete", item.delete, options, params)
);
}
if (item.post) {
requests.push(
makeRequest($refs, pattern, "post", item.post, options, params)
);
}
if (item.put) {
requests.push(
makeRequest($refs, pattern, "put", item.put, options, params)
);
}
if (item.patch) {
requests.push(
makeRequest($refs, pattern, "patch", item.patch, options, params)
);
}
if (item.head) {
requests.push(
makeRequest($refs, pattern, "head", item.head, options, params)
);
}
if (item.options) {
requests.push(
makeRequest($refs, pattern, "options", item.options, options, params)
);
}
methods.forEach((method) => {
const operation = item[method];
if (operation) {
requests.push(
makeRequest($refs, pattern, method, operation, options, params)
);
}
});

return requests;
}
Expand Down