Skip to content

Commit

Permalink
Refactor makeRequestsPropertyAssignment to use loop over HTTP methods
Browse files Browse the repository at this point in the history
  • Loading branch information
moetazbrayek1 committed Nov 27, 2023
1 parent 071b83e commit b6f5c14
Showing 1 changed file with 9 additions and 35 deletions.
44 changes: 9 additions & 35 deletions src/common/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,46 +141,20 @@ function makeRequestsPropertyAssignment(
) {
const requests: ts.PropertyAssignment[] = [];
const params = item.parameters;
const methods = ["get", "delete", "post", "put", "patch", "head", "options"];

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 => {
if (item[method]) {

Check failure on line 147 in src/common/requests.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'PathItemObject<{}>'.

Check failure on line 147 in src/common/requests.ts

View workflow job for this annotation

GitHub Actions / build (15.x)

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'PathItemObject<{}>'.

Check failure on line 147 in src/common/requests.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'PathItemObject<{}>'.
requests.push(
makeRequest($refs, pattern, method, item[method], options, params)

Check failure on line 149 in src/common/requests.ts

View workflow job for this annotation

GitHub Actions / build (14.x)

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'PathItemObject<{}>'.

Check failure on line 149 in src/common/requests.ts

View workflow job for this annotation

GitHub Actions / build (15.x)

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'PathItemObject<{}>'.

Check failure on line 149 in src/common/requests.ts

View workflow job for this annotation

GitHub Actions / build (16.x)

Element implicitly has an 'any' type because expression of type 'string' can't be used to index type 'PathItemObject<{}>'.
);
}
});

return requests;
}


function isRequestBodyObject(
obj: OpenAPIV3.ReferenceObject | OpenAPIV3.RequestBodyObject
): obj is OpenAPIV3.RequestBodyObject {
Expand Down

0 comments on commit b6f5c14

Please sign in to comment.