0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

refactor(core): sort swagger tags

This commit is contained in:
Gao Sun 2023-11-12 22:17:54 +08:00
parent 0e0966d65d
commit e9d349737b
No known key found for this signature in database
GPG key ID: 13EBE123E4773688

View file

@ -158,9 +158,16 @@ export default function swaggerRoutes<T extends AnonymousRouter, R extends Route
});
const pathMap = new Map<string, OpenAPIV3.PathItemObject>();
const tags = new Set<string>();
// Group routes by path
for (const { path, method, operation } of routes) {
if (operation.tags) {
// Collect all tags for sorting
for (const tag of operation.tags) {
tags.add(tag);
}
}
pathMap.set(path, { ...pathMap.get(path), [method]: operation });
}
@ -193,13 +200,19 @@ export default function swaggerRoutes<T extends AnonymousRouter, R extends Route
{}
),
},
tags: [...tags].map((tag) => ({ name: tag })),
};
ctx.body = supplementDocuments.reduce(
const data = supplementDocuments.reduce(
(document, supplement) => deepmerge(document, supplement, { arrayMerge: mergeParameters }),
baseDocument
);
ctx.body = {
...data,
tags: data.tags?.slice().sort((tagA, tagB) => tagA.name.localeCompare(tagB.name)),
};
return next();
});
}