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:
parent
0e0966d65d
commit
e9d349737b
1 changed files with 14 additions and 1 deletions
|
@ -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();
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue