Skip to content

Conversation

@ljluestc
Copy link

@ljluestc ljluestc commented Jan 4, 2026

Description: This PR introduces the ability to duplicate an entire interface classification (category) along with all its nested interfaces. This capability is essential for users needing to version APIs, replicate project structures, or create variations of existing categories without manual data entry.

Key Changes:

Backend (server/controllers/interface.js): Implemented the copyCat method which performs a deep copy of a category.
Deep Duplication: Iterates through all interfaces in the source category and creates copies in the new category.
Data Sanitization: Strips unique identifiers (_id, add_time, __v) from the source documents to ensuring clean insertions.
Conflict Resolution: Implements recursive path checking. If a duplicate
(project_id, path, method)
is found, it automatically appends _copy (or a timestamp) to the path to satisfy uniqueness constraints.
Router (server/router.js): Registered the new endpoint POST /api/interface/copy_cat.
Frontend (client/containers/Project/Interface/InterfaceList/InterfaceMenu.js): Added a "Copy" operation to the interface menu, allowing users to trigger the duplication directly from the sidebar.
API Endpoint:

http
POST /api/interface/copy_cat
Content-Type: application/json
{
"project_id": "Number | Required",
"catid": "Number | Required (Source Category ID)",
"desc": "String | Optional (Description for new category)"
}
Implementation Details:

Trigger: User clicks the copy icon on a category in the sidebar.
Process: The server creates a new category (e.g., "Login_copy").
Recursion: It fetches all interfaces from the source category.
Insertion: Each interface is validated against the existing paths in the project.
Fallback: If POST /api/login exists, the copy becomes POST /api/login_copy.
Checklist:

Backend logic for deep copying category and interfaces.
smart path conflict resolution (suffixing).
Frontend UI integration (sidebar menu icon).
Verified data integrity (all interface fields preserved).
Tests passed for path collision scenarios.
Screenshots: (Please attach screenshots of the new "Copy" icon in the sidebar and the resulting duplicated category here)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant