|
|
@@ -1,16 +1,50 @@
|
|
|
import { generateFiles } from "fumadocs-openapi";
|
|
|
|
|
|
-import { openapi } from "../src/lib/openapi";
|
|
|
+import { openapi, products } from "../src/lib/openapi";
|
|
|
|
|
|
-const outDir = "./content/docs/openapi/operation/route";
|
|
|
+const outDir = "./content/docs/openapi/";
|
|
|
|
|
|
export async function generateDocs() {
|
|
|
- await generateFiles({
|
|
|
- input: openapi,
|
|
|
- output: outDir,
|
|
|
- per: 'operation',
|
|
|
- includeDescription: true,
|
|
|
- });
|
|
|
+ await generateFiles({
|
|
|
+ input: openapi,
|
|
|
+ output: outDir,
|
|
|
+ per: "operation",
|
|
|
+ name: (output, document) => {
|
|
|
+ // Extract product name from the OpenAPI document info
|
|
|
+ const productName = getProductName(document.info.title || "unknown");
|
|
|
+
|
|
|
+ if (output.type === "operation") {
|
|
|
+ const operation =
|
|
|
+ document.paths?.[output.item.path]?.[output.item.method];
|
|
|
+ const operationId =
|
|
|
+ operation?.operationId ??
|
|
|
+ output.item.path.replaceAll(/[^a-zA-Z0-9]/g, "_");
|
|
|
+ return `${productName}/${operationId}`;
|
|
|
+ }
|
|
|
+
|
|
|
+ return `${productName}/webhooks/${output.item.name}`;
|
|
|
+ },
|
|
|
+ index: {
|
|
|
+ url: {
|
|
|
+ baseUrl: "/openapi/",
|
|
|
+ contentDir: "./content/docs/openapi",
|
|
|
+ },
|
|
|
+ items: Object.keys(products).map((productName) => ({
|
|
|
+ path: `${productName}/index.mdx`,
|
|
|
+ })),
|
|
|
+ },
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function getProductName(title: string): string {
|
|
|
+ // Match the title to a product name
|
|
|
+ const titleLower = title.toLowerCase();
|
|
|
+ for (const [name] of Object.entries(products)) {
|
|
|
+ if (titleLower.includes(name)) {
|
|
|
+ return name;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return "unknown";
|
|
|
}
|
|
|
|
|
|
-await generateDocs();
|
|
|
+await generateDocs();
|