[PR #5524] [MERGED] chore: mock server name validation and prevent duplicates #5241

Closed
opened 2026-03-17 02:42:34 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hoppscotch/hoppscotch/pull/5524
Author: @mirarifhasan
Created: 10/29/2025
Status: Merged
Merged: 10/29/2025
Merged by: @nahidhasan94

Base: nextHead: fix/mock-server-backend-followup


📝 Commits (3)

  • 2a963a3 chore: mock server name validation and prevent duplicates
  • c0642d3 refactor: mock server name validation pattern
  • cdf3713 chore: remove duplicate mock server collection check

📊 Changes

1 file changed (+16 additions, -3 deletions)

View changed files

📝 packages/hoppscotch-backend/src/mock-server/mock-server.model.ts (+16 -3)

📄 Description

Closes #

What's changed

This pull request introduces improved validation and error handling for mock server creation and updates in the backend. The most significant changes are the relaxed name validation rules for mock servers and the addition of a check to prevent duplicate mock servers for the same collection.

Validation improvements:

  • Relaxed the validation for the name field in both CreateMockServerInput and UpdateMockServerInput classes: replaced @IsAlphanumeric() with @Matches(/^[a-zA-Z0-9 ._-]+$/) to allow spaces, dots, underscores, and hyphens, and added @IsString() for type safety. [1] [2] [3]

Error handling enhancements:

  • Added a check in MockServerService to prevent creating a mock server with a collection ID that already exists and is not deleted, returning a MOCK_SERVER_ALREADY_EXISTS error if found. [1] [2]

Notes to reviewers

Nil


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hoppscotch/hoppscotch/pull/5524 **Author:** [@mirarifhasan](https://github.com/mirarifhasan) **Created:** 10/29/2025 **Status:** ✅ Merged **Merged:** 10/29/2025 **Merged by:** [@nahidhasan94](https://github.com/nahidhasan94) **Base:** `next` ← **Head:** `fix/mock-server-backend-followup` --- ### 📝 Commits (3) - [`2a963a3`](https://github.com/hoppscotch/hoppscotch/commit/2a963a3c46e59b71ce5274a63a3cbbdfe8c653b7) chore: mock server name validation and prevent duplicates - [`c0642d3`](https://github.com/hoppscotch/hoppscotch/commit/c0642d31f0f1b138a4fb0005ca5c478714b98026) refactor: mock server name validation pattern - [`cdf3713`](https://github.com/hoppscotch/hoppscotch/commit/cdf3713fe38b3de3f5ab2855316c0360da79d5b0) chore: remove duplicate mock server collection check ### 📊 Changes **1 file changed** (+16 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `packages/hoppscotch-backend/src/mock-server/mock-server.model.ts` (+16 -3) </details> ### 📄 Description <!-- Thanks for creating this pull request 🤗 Please make sure that the pull request is limited to one type (docs, feature, etc.) and keep it as small as possible. You can open multiple prs instead of opening a huge one. --> <!-- If this pull request closes an issue, please mention the issue number below --> Closes # <!-- Issue # here --> <!-- Add an introduction into what this PR tries to solve in a couple of sentences --> ### What's changed <!-- Describe point by point the different things you have changed in this PR --> This pull request introduces improved validation and error handling for mock server creation and updates in the backend. The most significant changes are the relaxed name validation rules for mock servers and the addition of a check to prevent duplicate mock servers for the same collection. **Validation improvements:** * Relaxed the validation for the `name` field in both `CreateMockServerInput` and `UpdateMockServerInput` classes: replaced `@IsAlphanumeric()` with `@Matches(/^[a-zA-Z0-9 ._-]+$/)` to allow spaces, dots, underscores, and hyphens, and added `@IsString()` for type safety. [[1]](diffhunk://#diff-93cc9f5dc50179e0fc4d1e7f4f3ab8a5e42a49ded6adb276524b9620a82c8d8fL10-R13) [[2]](diffhunk://#diff-93cc9f5dc50179e0fc4d1e7f4f3ab8a5e42a49ded6adb276524b9620a82c8d8fR106-R112) [[3]](diffhunk://#diff-93cc9f5dc50179e0fc4d1e7f4f3ab8a5e42a49ded6adb276524b9620a82c8d8fR157-R164) **Error handling enhancements:** * Added a check in `MockServerService` to prevent creating a mock server with a collection ID that already exists and is not deleted, returning a `MOCK_SERVER_ALREADY_EXISTS` error if found. [[1]](diffhunk://#diff-c8edfb7c8a3b0950506b59351c3ce1a89ec044d548f2ab0d1f81f43d97f65d4aR22) [[2]](diffhunk://#diff-c8edfb7c8a3b0950506b59351c3ce1a89ec044d548f2ab0d1f81f43d97f65d4aR315-R325) <!-- You can also choose to add a list of changes and if they have been completed or not by using the markdown to-do list syntax - [ ] Not Completed - [x] Completed --> ### Notes to reviewers <!-- Any information you feel the reviewer should know about when reviewing your PR --> Nil --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-17 02:42:34 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/hoppscotch#5241
No description provided.