({ order })
| 1 | export default function SortMethods({ order }) { |
| 2 | console.log("re-ordering methods"); |
| 3 | return { |
| 4 | PathItem: { |
| 5 | leave(pathItem) { |
| 6 | // start with the default ordering, override with config if we have it |
| 7 | let methodList = ["get", "post", "patch", "put", "delete"]; |
| 8 | if (order) { |
| 9 | methodList = order; |
| 10 | } |
| 11 | |
| 12 | let existingMethods = Object.getOwnPropertyNames(pathItem); |
| 13 | |
| 14 | for (const method of methodList) { |
| 15 | const operation = pathItem[method]; |
| 16 | // For each defined operation, delete it and re-add it to the path so they will be in the correct order: |
| 17 | if (operation) { |
| 18 | // remove it from the methods list so we know we processed it |
| 19 | existingMethods = existingMethods.filter((x) => x != method); |
| 20 | delete pathItem[method]; |
| 21 | pathItem[method] = operation; |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | // now re-add any methods that weren't in the list |
| 26 | for (const method of existingMethods) { |
| 27 | const operation = pathItem[method]; |
| 28 | // Delete and re-add unprocessed operations to the path so they will be in the correct order: |
| 29 | if (operation) { |
| 30 | delete pathItem[method]; |
| 31 | pathItem[method] = operation; |
| 32 | } |
| 33 | } |
| 34 | }, |
| 35 | }, |
| 36 | }; |
| 37 | } |
nothing calls this directly
no outgoing calls
no test coverage detected