@@ -7,15 +7,22 @@ import {
77 registerEnumType ,
88} from '@nestjs/graphql' ;
99import {
10- IsAlphanumeric ,
1110 IsNumber ,
1211 IsOptional ,
12+ IsString ,
13+ Matches ,
1314 Max ,
1415 MaxLength ,
1516 MinLength ,
1617} from 'class-validator' ;
1718import { WorkspaceType } from 'src/types/WorkspaceTypes' ;
1819
20+ // Regex pattern for mock server name validation
21+ // Allows letters, numbers, spaces, dots, underscores, and hyphens
22+ const MOCK_SERVER_NAME_PATTERN = / ^ [ a - z A - Z 0 - 9 . _ - ] + $ / ;
23+ const MOCK_SERVER_NAME_ERROR_MESSAGE =
24+ 'Name can only contain letters, numbers, spaces, dots, underscores, and hyphens' ;
25+
1926@ObjectType ( )
2027export class MockServer {
2128 @Field ( ( ) => ID , {
@@ -102,9 +109,12 @@ export class CreateMockServerInput {
102109 @Field ( {
103110 description : 'Name of the mock server' ,
104111 } )
112+ @IsString ( )
105113 @MinLength ( 1 )
106114 @MaxLength ( 255 )
107- @IsAlphanumeric ( )
115+ @Matches ( MOCK_SERVER_NAME_PATTERN , {
116+ message : MOCK_SERVER_NAME_ERROR_MESSAGE ,
117+ } )
108118 name : string ;
109119
110120 @Field ( {
@@ -149,10 +159,13 @@ export class UpdateMockServerInput {
149159 nullable : true ,
150160 description : 'Name of the mock server' ,
151161 } )
162+ @IsString ( )
152163 @IsOptional ( )
153164 @MinLength ( 1 )
154165 @MaxLength ( 255 )
155- @IsAlphanumeric ( )
166+ @Matches ( MOCK_SERVER_NAME_PATTERN , {
167+ message : MOCK_SERVER_NAME_ERROR_MESSAGE ,
168+ } )
156169 name ?: string ;
157170
158171 @Field ( {
0 commit comments