flipped-aurora/gin-vue-admin · warning
存在相同api路径
Error message
存在相同api路径
What it means
UpdateApi guards against renaming an API's path/method into a collision with a different existing row. It loads a record matching the new path+method; if found and its primary key differs from the record being updated (duplicateApi.ID != api.ID), it returns "存在相同api路径". Updating a row to its own current path+method is allowed.
Source
Thrown at server/service/system/sys_api.go:289
//@author: [piexlmax](https://github.com/piexlmax)
//@function: UpdateApi
//@description: 根据id更新api
//@param: api model.SysApi
//@return: err error
func (apiService *ApiService) UpdateApi(ctx context.Context, api system.SysApi) (err error) {
var oldA system.SysApi
err = global.GVA_DB.WithContext(ctx).First(&oldA, "id = ?", api.ID).Error
if oldA.Path != api.Path || oldA.Method != api.Method {
var duplicateApi system.SysApi
if ferr := global.GVA_DB.WithContext(ctx).First(&duplicateApi, "path = ? AND method = ?", api.Path, api.Method).Error; ferr != nil {
if !errors.Is(ferr, gorm.ErrRecordNotFound) {
return ferr
}
} else {
if duplicateApi.ID != api.ID {
return errors.New("存在相同api路径")
}
}
}
if err != nil {
return err
}
err = CasbinServiceApp.UpdateCasbinApi(ctx, oldA.Path, api.Path, oldA.Method, api.Method)
if err != nil {
return err
}
return global.GVA_DB.WithContext(ctx).Save(&api).Error
}
//@author: [piexlmax](https://github.com/piexlmax)
//@function: DeleteApisByIdsView on GitHub (pinned to 3136500ef3)
Solutions
- Pick a path+method pair not present in the sys_api table (check the API list page first).
- If the two rows should be one, delete the other duplicate row and retry the update.
- Ensure the ID in the update payload matches the row you intend to edit; stale frontend data can make the service compare against the wrong ID.
Defensive patterns
Strategy: validation
Validate before calling
const dup = list.find(a => a.path === form.path && a.method === form.method)
if (dup && dup.ID !== form.ID) throw new Error('目标 path+method 已被另一条记录占用 (ID=' + dup.ID + ')') Try / catch
try {
await updateApi(form)
} catch (e) {
if (String(e?.msg).includes('存在相同api路径')) {
ElMessage.warning('其他 API 已使用该 path+method,请换一个或删除冲突记录')
} else { throw e }
} Prevention
- Exclude the record's own ID when checking for collisions in the UI.
- Refresh the API list before bulk edits so IDs in the payload are current.
- Run a uniqueness check (path, method) over the whole table after imports.
- Avoid copy-paste edits that only change the description while keeping a colliding path.
When it happens
Trigger: Calling PUT /api/updateApi with a changed path or method that already exists on another sys_api row (different ID). E.g. editing API id=5 to path=/base/login method=POST when id=12 already has that pair.
Common situations: Merging two environment copies of the API table then editing entries; a typo causes the new path to equal another endpoint's path; bulk edits applied to multiple rows without deduplication.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/c2fe330dbadc4f84.
Report an issue: GitHub.