persona-community-5/.pnpm-store/v3/files/f6/cee41ea570c0e1ba98e6287d7c37d55cd8bc60cabfaf227e5e5e71b1f15bcf572c2402b8e07d556e61d882797fb9d6f72c57864de265bc755f3b7006155ced
rdev-worker a1d0d1bf1c
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
build: /implement-feature community-ui --requirements 'Build the React commu...
2026-02-24 08:22:30 +00:00

44 lines
1.4 KiB
Plaintext

import type ts from "typescript";
import { tsEnum } from "../lib/ts.js";
import { getEntries } from "../lib/utils.js";
import type { PathsObject } from "../types.js";
export default function makeApiPathsEnum(pathsObject: PathsObject): ts.EnumDeclaration {
const enumKeys = [];
const enumMetaData = [];
for (const [url, pathItemObject] of getEntries(pathsObject)) {
for (const [method, operation] of Object.entries(pathItemObject)) {
if (!["get", "put", "post", "delete", "options", "head", "patch", "trace"].includes(method)) {
continue;
}
// Generate a name from the operation ID
let pathName: string;
if (operation.operationId) {
pathName = operation.operationId;
} else {
// If the operation ID is not present, construct a name from the method and path
pathName = (method + url)
.split("/")
.map((part) => {
const capitalised = part.charAt(0).toUpperCase() + part.slice(1);
// Remove any characters not allowed as enum keys, and attempt to remove
// named parameters.
return capitalised.replace(/{.*}|:.*|[^a-zA-Z\d_]+/, "");
})
.join("");
}
enumKeys.push(url);
enumMetaData.push({
name: pathName,
});
}
}
return tsEnum("ApiPaths", enumKeys, enumMetaData, {
export: true,
});
}