@@ -29,8 +29,14 @@ import { KotlinResolversPluginRawConfig } from './config.js';
2929import {
3030 VALIDATION_DIRECTIVES ,
3131 parseDirectiveArgs ,
32+ DirectiveArgument ,
3233} from './directive-mapping.js' ;
3334
35+ export interface ValidationAnnotation {
36+ name : string ;
37+ params ?: DirectiveArgument [ ] ;
38+ }
39+
3440export const KOTLIN_SCALARS = {
3541 ID : 'Any' ,
3642 String : 'String' ,
@@ -186,12 +192,12 @@ ${enumValues}
186192 /**
187193 * Extract validation annotations from field directives
188194 */
189- private extractValidationAnnotations ( field : InputValueDefinitionNode ) : string [ ] {
195+ private extractValidationAnnotations ( field : InputValueDefinitionNode ) : ValidationAnnotation [ ] {
190196 if ( ! field . directives || field . directives . length === 0 ) {
191197 return [ ] ;
192198 }
193199
194- const annotations : string [ ] = [ ] ;
200+ const annotations : ValidationAnnotation [ ] = [ ] ;
195201
196202 for ( const directive of field . directives ) {
197203 const directiveName = `@${ directive . name . value } ` ;
@@ -201,13 +207,15 @@ ${enumValues}
201207 const annotationName = VALIDATION_DIRECTIVES [ directiveName ] ;
202208
203209 // Parse directive arguments
204- let annotationParams = '' ;
210+ let annotationParams : DirectiveArgument [ ] | undefined ;
205211 if ( directive . arguments && directive . arguments . length > 0 ) {
206- const params = parseDirectiveArgs ( directiveName , Array . from ( directive . arguments ) ) ;
207- annotationParams = `(${ params . join ( ', ' ) } )` ;
212+ annotationParams = parseDirectiveArgs ( directiveName , Array . from ( directive . arguments ) ) ;
208213 }
209214
210- annotations . push ( `${ annotationName } ${ annotationParams } ` ) ;
215+ annotations . push ( {
216+ name : annotationName ,
217+ params : annotationParams
218+ } ) ;
211219 }
212220 }
213221
@@ -217,10 +225,15 @@ ${enumValues}
217225 /**
218226 * Format validation annotations
219227 */
220- private formatValidationAnnotations ( annotations : string [ ] ) : string [ ] {
228+ private formatValidationAnnotations ( annotations : ValidationAnnotation [ ] ) : string [ ] {
221229 // All validation annotations need @field : prefix because they are field annotations, not class annotations
222230 const prefix = '@field:' ;
223- return annotations . map ( annotation => `${ prefix } ${ annotation } ` ) ;
231+ return annotations . map ( annotation => {
232+ const annotationString = annotation . params
233+ ? `${ annotation . name } (${ annotation . params . map ( param => `${ param . name } = ${ param . value } ` ) . join ( ', ' ) } )`
234+ : annotation . name ;
235+ return `${ prefix } ${ annotationString } ` ;
236+ } ) ;
224237 }
225238
226239 /**
@@ -242,12 +255,12 @@ ${enumValues}
242255 /**
243256 * Extract validation annotations from object type field directives
244257 */
245- private extractValidationAnnotationsForField ( field : FieldDefinitionNode ) : string [ ] {
258+ private extractValidationAnnotationsForField ( field : FieldDefinitionNode ) : ValidationAnnotation [ ] {
246259 if ( ! field . directives || field . directives . length === 0 ) {
247260 return [ ] ;
248261 }
249262
250- const annotations : string [ ] = [ ] ;
263+ const annotations : ValidationAnnotation [ ] = [ ] ;
251264
252265 for ( const directive of field . directives ) {
253266 const directiveName = `@${ directive . name . value } ` ;
@@ -257,13 +270,15 @@ ${enumValues}
257270 const annotationName = VALIDATION_DIRECTIVES [ directiveName ] ;
258271
259272 // Parse directive arguments
260- let annotationParams = '' ;
273+ let annotationParams : DirectiveArgument [ ] | undefined ;
261274 if ( directive . arguments && directive . arguments . length > 0 ) {
262- const params = parseDirectiveArgs ( directiveName , Array . from ( directive . arguments ) ) ;
263- annotationParams = `(${ params . join ( ', ' ) } )` ;
275+ annotationParams = parseDirectiveArgs ( directiveName , Array . from ( directive . arguments ) ) ;
264276 }
265277
266- annotations . push ( `${ annotationName } ${ annotationParams } ` ) ;
278+ annotations . push ( {
279+ name : annotationName ,
280+ params : annotationParams
281+ } ) ;
267282 }
268283 }
269284
@@ -283,8 +298,12 @@ ${enumValues}
283298 return [ ] ;
284299 }
285300
286- // For object type fields, annotations are added directly to constructor parameters
287- return annotations ;
301+ // For object type fields, format annotations without @field: prefix since they're constructor parameters
302+ return annotations . map ( annotation => {
303+ return annotation . params
304+ ? `@${ annotation . name } (${ annotation . params . map ( param => `${ param . name } = ${ param . value } ` ) . join ( ', ' ) } )`
305+ : `@${ annotation . name } ` ;
306+ } ) ;
288307 }
289308
290309 protected buildInputTransfomer (
0 commit comments