Skip to content

Commit 4e1922b

Browse files
committed
Deterministic OpenAPI spec generation
1 parent 114b1d3 commit 4e1922b

5 files changed

Lines changed: 8355 additions & 8349 deletions

File tree

apps/backend/scripts/generate-openapi-fumadocs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async function main() {
2929
// Generate OpenAPI specs for each audience (let parseOpenAPI handle the filtering)
3030
const filePathPrefix = path.resolve(process.platform === "win32" ? "apps/src/app/api/latest" : "src/app/api/latest");
3131
const importPathPrefix = "@/app/api/latest";
32-
const filePaths = [...await glob(filePathPrefix + "/**/route.{js,jsx,ts,tsx}")];
32+
const filePaths = [...await glob(filePathPrefix + "/**/route.{js,jsx,ts,tsx}")].sort((a, b) => a.localeCompare(b));
3333

3434
const endpoints = new Map(await Promise.all(filePaths.map(async (filePath) => {
3535
if (!filePath.startsWith(filePathPrefix)) {

apps/backend/src/lib/openapi.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ export function parseOpenAPI(options: {
3434
)]
3535
))
3636
.filter(([_, handlersByMethod]) => Object.keys(handlersByMethod).length > 0)
37-
.sort(([_a, handlersByMethodA], [_b, handlersByMethodB]) => stringCompare((Object.values(handlersByMethodA)[0] as any).tags[0] ?? "", (Object.values(handlersByMethodB)[0] as any).tags[0] ?? "")),
37+
.sort(([pathA, handlersByMethodA], [pathB, handlersByMethodB]) => {
38+
const tagComparison = stringCompare((Object.values(handlersByMethodA)[0] as any).tags[0] ?? "", (Object.values(handlersByMethodB)[0] as any).tags[0] ?? "");
39+
if (tagComparison !== 0) {
40+
return tagComparison;
41+
}
42+
return stringCompare(pathA, pathB);
43+
}),
3844
),
3945
};
4046
}

0 commit comments

Comments
 (0)