更新api
This commit is contained in:
+14
-8
@@ -34,15 +34,21 @@ export default {
|
||||
// 这里剥掉 -controller 后缀并转为 PascalCase,使 wormhole 生成的
|
||||
// API 路径(Base.getUserInfo 等)与 Apis.Base.xxx 调用风格一致。
|
||||
// 由于转换结果是合法 JS 标识符,wormhole 会原样保留、不做 camelCase 改写。
|
||||
// springdoc v3 的 tag 有两种形态,都要能正确转为 PascalCase 且无 Controller 后缀:
|
||||
// - Pascal+Controller:SysGroupController -> SysGroup
|
||||
// - kebab+controller:sys-group-controller -> SysGroup
|
||||
// 关键:剥掉尾部 Controller 后,要在 camelCase 边界补空格再逐段首字母大写,
|
||||
// 否则 SysGroup -> Sysgroup(后面全被 toLowerCase 压成小写)会让运行时查不到。
|
||||
const toNamespace = (tag: string): string => {
|
||||
const stripped = tag.replace(/controller$/i, "");
|
||||
const withSpaces = stripped.replace(/([a-z0-9])([A-Z])/g, "$1 $2");
|
||||
const parts = withSpaces.split(/[^a-zA-Z0-9]+/).filter(Boolean);
|
||||
return parts
|
||||
.map((p: string) => p.charAt(0).toUpperCase() + p.slice(1).toLowerCase())
|
||||
.join("");
|
||||
};
|
||||
if (Array.isArray(apiDescriptor.tags)) {
|
||||
apiDescriptor.tags = apiDescriptor.tags.map((tag: string) => {
|
||||
const stripped = tag.replace(/-?controller$/i, "");
|
||||
return stripped
|
||||
.split(/[-_\s]+/)
|
||||
.filter(Boolean)
|
||||
.map((w: string) => w.charAt(0).toUpperCase() + w.slice(1).toLowerCase())
|
||||
.join("");
|
||||
});
|
||||
apiDescriptor.tags = apiDescriptor.tags.map(toNamespace);
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user