Skip to content

Instantly share code, notes, and snippets.

@cdbkr
Created December 11, 2025 15:04
Show Gist options
  • Select an option

  • Save cdbkr/9198f609fc11e2e5021248c2b232cd0e to your computer and use it in GitHub Desktop.

Select an option

Save cdbkr/9198f609fc11e2e5021248c2b232cd0e to your computer and use it in GitHub Desktop.
groupEndpoints function
const groupEndpoints = (spec) => {
const groups = new Map();
Object.entries(spec.paths || {}).forEach(([path, methods]) => {
const resource = path.split('/').filter(Boolean)[0] || 'root';
if (!groups.has(resource)) {
groups.set(resource, []);
}
Object.entries(methods)
.filter(([_, op]) => op && typeof op === 'object')
.forEach(([method, operation]) => {
groups.get(resource).push(extractEndpoint(path, method, operation));
});
});
return groups;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment