@@ -156,15 +156,20 @@ export class Enum extends ReflectionObject {
156
156
* @param name Unique name within its namespace
157
157
* @param [values] Enum values as an object, by name
158
158
* @param [options] Declared options
159
+ * @param [comment] The comment for this enum
160
+ * @param [comments] The value comments for this enum
159
161
*/
160
- constructor ( name : string , values ?: { [ k : string ] : number } , options ?: { [ k : string ] : any } ) ;
162
+ constructor ( name : string , values ?: { [ k : string ] : number } , options ?: { [ k : string ] : any } , comment ?: string , comments ?: { [ k : string ] : string } ) ;
161
163
162
164
/** Enum values by id. */
163
165
public valuesById : { [ k : number ] : string } ;
164
166
165
167
/** Enum values by name. */
166
168
public values : { [ k : string ] : number } ;
167
169
170
+ /** Enum comment text. */
171
+ public comment : ( string | null ) ;
172
+
168
173
/** Value comment texts, if any. */
169
174
public comments : { [ k : string ] : string } ;
170
175
@@ -182,9 +187,10 @@ export class Enum extends ReflectionObject {
182
187
183
188
/**
184
189
* Converts this enum to an enum descriptor.
190
+ * @param [toJSONOptions] JSON conversion options
185
191
* @returns Enum descriptor
186
192
*/
187
- public toJSON ( ) : IEnum ;
193
+ public toJSON ( toJSONOptions ?: IToJSONOptions ) : IEnum ;
188
194
189
195
/**
190
196
* Adds a value to this enum.
@@ -288,8 +294,9 @@ export class FieldBase extends ReflectionObject {
288
294
* @param [rule="optional"] Field rule
289
295
* @param [extend] Extended type if different from parent
290
296
* @param [options] Declared options
297
+ * @param [comment] Comment associated with this field
291
298
*/
292
- constructor ( name : string , id : number , type : string , rule ?: ( string | { [ k : string ] : any } ) , extend ?: ( string | { [ k : string ] : any } ) , options ?: { [ k : string ] : any } ) ;
299
+ constructor ( name : string , id : number , type : string , rule ?: ( string | { [ k : string ] : any } ) , extend ?: ( string | { [ k : string ] : any } ) , options ?: { [ k : string ] : any } , comment ?: string ) ;
293
300
294
301
/** Field rule, if any. */
295
302
public rule ?: string ;
@@ -342,11 +349,15 @@ export class FieldBase extends ReflectionObject {
342
349
/** Sister-field within the declaring namespace if an extended field. */
343
350
public declaringField : ( Field | null ) ;
344
351
352
+ /** Comment for this field. */
353
+ public comment : ( string | null ) ;
354
+
345
355
/**
346
356
* Converts this field to a field descriptor.
357
+ * @param [toJSONOptions] JSON conversion options
347
358
* @returns Field descriptor
348
359
*/
349
- public toJSON ( ) : IField ;
360
+ public toJSON ( toJSONOptions ?: IToJSONOptions ) : IField ;
350
361
351
362
/**
352
363
* Resolves this field's type references.
@@ -445,8 +456,9 @@ export class MapField extends FieldBase {
445
456
* @param keyType Key type
446
457
* @param type Value type
447
458
* @param [options] Declared options
459
+ * @param [comment] Comment associated with this field
448
460
*/
449
- constructor ( name : string , id : number , keyType : string , type : string , options ?: { [ k : string ] : any } ) ;
461
+ constructor ( name : string , id : number , keyType : string , type : string , options ?: { [ k : string ] : any } , comment ?: string ) ;
450
462
451
463
/** Key type. */
452
464
public keyType : string ;
@@ -465,9 +477,10 @@ export class MapField extends FieldBase {
465
477
466
478
/**
467
479
* Converts this map field to a map field descriptor.
480
+ * @param [toJSONOptions] JSON conversion options
468
481
* @returns Map field descriptor
469
482
*/
470
- public toJSON ( ) : IMapField ;
483
+ public toJSON ( toJSONOptions ?: IToJSONOptions ) : IMapField ;
471
484
472
485
/**
473
486
* Map field decorator (TypeScript).
@@ -586,8 +599,9 @@ export class Method extends ReflectionObject {
586
599
* @param [requestStream] Whether the request is streamed
587
600
* @param [responseStream] Whether the response is streamed
588
601
* @param [options] Declared options
602
+ * @param [comment] The comment for this method
589
603
*/
590
- constructor ( name : string , type : ( string | undefined ) , requestType : string , responseType : string , requestStream ?: ( boolean | { [ k : string ] : any } ) , responseStream ?: ( boolean | { [ k : string ] : any } ) , options ?: { [ k : string ] : any } ) ;
604
+ constructor ( name : string , type : ( string | undefined ) , requestType : string , responseType : string , requestStream ?: ( boolean | { [ k : string ] : any } ) , responseStream ?: ( boolean | { [ k : string ] : any } ) , options ?: { [ k : string ] : any } , comment ?: string ) ;
591
605
592
606
/** Method type. */
593
607
public type : string ;
@@ -610,6 +624,9 @@ export class Method extends ReflectionObject {
610
624
/** Resolved response type. */
611
625
public resolvedResponseType : ( Type | null ) ;
612
626
627
+ /** Comment for this method */
628
+ public comment : ( string | null ) ;
629
+
613
630
/**
614
631
* Constructs a method from a method descriptor.
615
632
* @param name Method name
@@ -621,9 +638,10 @@ export class Method extends ReflectionObject {
621
638
622
639
/**
623
640
* Converts this method to a method descriptor.
641
+ * @param [toJSONOptions] JSON conversion options
624
642
* @returns Method descriptor
625
643
*/
626
- public toJSON ( ) : IMethod ;
644
+ public toJSON ( toJSONOptions ?: IToJSONOptions ) : IMethod ;
627
645
}
628
646
629
647
/** Method descriptor. */
@@ -670,9 +688,10 @@ export class Namespace extends NamespaceBase {
670
688
/**
671
689
* Converts an array of reflection objects to JSON.
672
690
* @param array Object array
691
+ * @param [toJSONOptions] JSON conversion options
673
692
* @returns JSON object or `undefined` when array is empty
674
693
*/
675
- public static arrayToJSON ( array : ReflectionObject [ ] ) : ( { [ k : string ] : any } | undefined ) ;
694
+ public static arrayToJSON ( array : ReflectionObject [ ] , toJSONOptions ?: IToJSONOptions ) : ( { [ k : string ] : any } | undefined ) ;
676
695
677
696
/**
678
697
* Tests if the specified id is reserved.
@@ -702,9 +721,10 @@ export abstract class NamespaceBase extends ReflectionObject {
702
721
703
722
/**
704
723
* Converts this namespace to a namespace descriptor.
724
+ * @param [toJSONOptions] JSON conversion options
705
725
* @returns Namespace descriptor
706
726
*/
707
- public toJSON ( ) : INamespace ;
727
+ public toJSON ( toJSONOptions ?: IToJSONOptions ) : INamespace ;
708
728
709
729
/**
710
730
* Adds nested objects to this namespace from nested object descriptors.
@@ -921,15 +941,19 @@ export class OneOf extends ReflectionObject {
921
941
* @param name Oneof name
922
942
* @param [fieldNames] Field names
923
943
* @param [options] Declared options
944
+ * @param [comment] Comment associated with this field
924
945
*/
925
- constructor ( name : string , fieldNames ?: ( string [ ] | { [ k : string ] : any } ) , options ?: { [ k : string ] : any } ) ;
946
+ constructor ( name : string , fieldNames ?: ( string [ ] | { [ k : string ] : any } ) , options ?: { [ k : string ] : any } , comment ?: string ) ;
926
947
927
948
/** Field names that belong to this oneof. */
928
949
public oneof : string [ ] ;
929
950
930
951
/** Fields that belong to this oneof as an array for iteration. */
931
952
public readonly fieldsArray : Field [ ] ;
932
953
954
+ /** Comment for this field. */
955
+ public comment : ( string | null ) ;
956
+
933
957
/**
934
958
* Constructs a oneof from a oneof descriptor.
935
959
* @param name Oneof name
@@ -941,9 +965,10 @@ export class OneOf extends ReflectionObject {
941
965
942
966
/**
943
967
* Converts this oneof to a oneof descriptor.
968
+ * @param [toJSONOptions] JSON conversion options
944
969
* @returns Oneof descriptor
945
970
*/
946
- public toJSON ( ) : IOneOf ;
971
+ public toJSON ( toJSONOptions ?: IToJSONOptions ) : IOneOf ;
947
972
948
973
/**
949
974
* Adds a field to this oneof and removes it from its current parent, if any.
@@ -1016,6 +1041,16 @@ export interface IParseOptions {
1016
1041
1017
1042
/** Keeps field casing instead of converting to camel case */
1018
1043
keepCase ?: boolean ;
1044
+
1045
+ /** Recognize double-slash comments in addition to doc-block comments. */
1046
+ alternateCommentMode ?: boolean ;
1047
+ }
1048
+
1049
+ /** Options modifying the behavior of JSON serialization. */
1050
+ export interface IToJSONOptions {
1051
+
1052
+ /** Serializes comments. */
1053
+ keepComments ?: boolean ;
1019
1054
}
1020
1055
1021
1056
/**
@@ -1345,9 +1380,10 @@ export class Service extends NamespaceBase {
1345
1380
1346
1381
/**
1347
1382
* Converts this service to a service descriptor.
1383
+ * @param [toJSONOptions] JSON conversion options
1348
1384
* @returns Service descriptor
1349
1385
*/
1350
- public toJSON ( ) : IService ;
1386
+ public toJSON ( toJSONOptions ?: IToJSONOptions ) : IService ;
1351
1387
1352
1388
/** Methods of this service as an array for iteration. */
1353
1389
public readonly methodsArray : Method [ ] ;
@@ -1497,9 +1533,10 @@ export class Type extends NamespaceBase {
1497
1533
1498
1534
/**
1499
1535
* Converts this message type to a message type descriptor.
1536
+ * @param [toJSONOptions] JSON conversion options
1500
1537
* @returns Message type descriptor
1501
1538
*/
1502
- public toJSON ( ) : IType ;
1539
+ public toJSON ( toJSONOptions ?: IToJSONOptions ) : IType ;
1503
1540
1504
1541
/**
1505
1542
* Adds a nested object to this type.
0 commit comments