1
1
using System . Text . RegularExpressions ;
2
2
using Microsoft . Extensions . Primitives ;
3
+ using Microsoft . Net . Http . Headers ;
3
4
4
5
namespace NpgsqlRest . Defaults ;
5
6
@@ -173,6 +174,11 @@ internal static class DefaultCommentParser
173
174
}
174
175
else
175
176
{
177
+
178
+ var routineDescription = string . Concat ( routine . Type , " " , routine . Schema , "." , routine . Name ) ;
179
+ var urlDescription = string . Concat ( routineEndpoint . Method . ToString ( ) , " " , routineEndpoint . Url ) ;
180
+ var description = string . Concat ( routineDescription , " mapped to " , urlDescription ) ;
181
+
176
182
string [ ] lines = comment . Split ( newlineSeparator , StringSplitOptions . RemoveEmptyEntries ) ;
177
183
routineEndpoint . CommentWordLines = new string [ lines . Length ] [ ] ;
178
184
bool hasHttpTag = false ;
@@ -267,15 +273,15 @@ internal static class DefaultCommentParser
267
273
}
268
274
else
269
275
{
270
- logger ? . InvalidHttpMethodComment ( words [ 1 ] , routine . Schema , routine . Name , routineEndpoint . Method ) ;
276
+ logger ? . InvalidHttpMethodComment ( words [ 1 ] , description , routineEndpoint . Method ) ;
271
277
}
272
278
}
273
279
if ( len == 3 )
274
280
{
275
281
string urlPathSegment = words [ 2 ] ;
276
282
if ( ! Uri . TryCreate ( urlPathSegment , UriKind . Relative , out Uri ? uri ) )
277
283
{
278
- logger ? . InvalidUrlPathSegmentComment ( urlPathSegment , routine . Schema , routine . Name , routineEndpoint . Url ) ;
284
+ logger ? . InvalidUrlPathSegmentComment ( urlPathSegment , description , routineEndpoint . Url ) ;
279
285
}
280
286
else
281
287
{
@@ -290,8 +296,10 @@ internal static class DefaultCommentParser
290
296
{
291
297
if ( options . LogAnnotationSetInfo )
292
298
{
293
- logger ? . CommentSetHttp ( routine . Type , routine . Schema , routine . Name , routineEndpoint . Method , routineEndpoint . Url ) ;
299
+ logger ? . CommentSetHttp ( description , routineEndpoint . Method , routineEndpoint . Url ) ;
294
300
}
301
+ urlDescription = string . Concat ( routineEndpoint . Method . ToString ( ) , " " , routineEndpoint . Url ) ;
302
+ description = string . Concat ( routineDescription , " mapped to " , urlDescription ) ;
295
303
}
296
304
}
297
305
@@ -313,14 +321,14 @@ internal static class DefaultCommentParser
313
321
}
314
322
else
315
323
{
316
- logger ? . InvalidParameterTypeComment ( words [ 1 ] , routine . Schema , routine . Name , routineEndpoint . RequestParamType ) ;
324
+ logger ? . InvalidParameterTypeComment ( words [ 1 ] , description , routineEndpoint . RequestParamType ) ;
317
325
}
318
326
319
327
if ( originalParamType != routineEndpoint . RequestParamType )
320
328
{
321
329
if ( options . LogAnnotationSetInfo )
322
330
{
323
- logger ? . CommentSetParameterType ( routine . Type , routine . Schema , routine . Name , routineEndpoint . RequestParamType ) ;
331
+ logger ? . CommentSetParameterType ( description , routineEndpoint . RequestParamType ) ;
324
332
}
325
333
}
326
334
}
@@ -337,13 +345,13 @@ internal static class DefaultCommentParser
337
345
routineEndpoint . AuthorizeRoles = new ( words [ 1 ..] ) ;
338
346
if ( options . LogAnnotationSetInfo )
339
347
{
340
- logger ? . CommentSetAuthRoles ( routine . Type , routine . Schema , routine . Name , routineEndpoint . AuthorizeRoles ) ;
348
+ logger ? . CommentSetAuthRoles ( description , routineEndpoint . AuthorizeRoles ) ;
341
349
}
342
350
} else
343
351
{
344
352
if ( options . LogAnnotationSetInfo )
345
353
{
346
- logger ? . CommentSetAuth ( routine . Type , routine . Schema , routine . Name ) ;
354
+ logger ? . CommentSetAuth ( description ) ;
347
355
}
348
356
}
349
357
}
@@ -358,7 +366,7 @@ internal static class DefaultCommentParser
358
366
routineEndpoint . RequiresAuthorization = false ;
359
367
if ( options . LogAnnotationSetInfo )
360
368
{
361
- logger ? . CommentSetAnon ( routine . Type , routine . Schema , routine . Name ) ;
369
+ logger ? . CommentSetAnon ( description ) ;
362
370
}
363
371
}
364
372
@@ -374,14 +382,14 @@ internal static class DefaultCommentParser
374
382
{
375
383
if ( options . LogAnnotationSetInfo )
376
384
{
377
- logger ? . CommentSetTimeout ( routine . Type , routine . Schema , routine . Name , words [ 1 ] ) ;
385
+ logger ? . CommentSetTimeout ( description , words [ 1 ] ) ;
378
386
}
379
387
}
380
388
routineEndpoint . CommandTimeout = parsedTimeout ;
381
389
}
382
390
else
383
391
{
384
- logger ? . InvalidTimeoutComment ( words [ 1 ] , routine . Schema , routine . Name , routineEndpoint . CommandTimeout ) ;
392
+ logger ? . InvalidTimeoutComment ( words [ 1 ] , description , routineEndpoint . CommandTimeout ) ;
385
393
}
386
394
}
387
395
@@ -407,13 +415,13 @@ internal static class DefaultCommentParser
407
415
}
408
416
else
409
417
{
410
- logger ? . InvalidRequestHeadersModeComment ( words [ 1 ] , routine . Schema , routine . Name , routineEndpoint . RequestHeadersMode ) ;
418
+ logger ? . InvalidRequestHeadersModeComment ( words [ 1 ] , description , routineEndpoint . RequestHeadersMode ) ;
411
419
}
412
420
if ( routineEndpoint . RequestHeadersMode != options . RequestHeadersMode )
413
421
{
414
422
if ( options . LogAnnotationSetInfo )
415
423
{
416
- logger ? . CommentSetRequestHeadersMode ( routine . Type , routine . Schema , routine . Name , words [ 1 ] ) ;
424
+ logger ? . CommentSetRequestHeadersMode ( description , words [ 1 ] ) ;
417
425
}
418
426
}
419
427
}
@@ -432,7 +440,7 @@ internal static class DefaultCommentParser
432
440
{
433
441
if ( options . LogAnnotationSetInfo )
434
442
{
435
- logger ? . CommentSetRequestHeadersParamName ( routine . Type , routine . Schema , routine . Name , words [ 1 ] ) ;
443
+ logger ? . CommentSetRequestHeadersParamName ( description , words [ 1 ] ) ;
436
444
}
437
445
}
438
446
routineEndpoint . RequestHeadersParameterName = words [ 1 ] ;
@@ -453,7 +461,7 @@ internal static class DefaultCommentParser
453
461
{
454
462
if ( options . LogAnnotationSetInfo )
455
463
{
456
- logger ? . CommentSetBodyParamName ( routine . Type , routine . Schema , routine . Name , words [ 1 ] ) ;
464
+ logger ? . CommentSetBodyParamName ( description , words [ 1 ] ) ;
457
465
}
458
466
}
459
467
routineEndpoint . BodyParameterName = words [ 1 ] ;
@@ -479,13 +487,13 @@ internal static class DefaultCommentParser
479
487
}
480
488
else
481
489
{
482
- logger ? . InvalidResponseNullHandlingModeComment ( words [ 1 ] , routine . Schema , routine . Name , routineEndpoint . TextResponseNullHandling ) ;
490
+ logger ? . InvalidResponseNullHandlingModeComment ( words [ 1 ] , description , routineEndpoint . TextResponseNullHandling ) ;
483
491
}
484
492
if ( routineEndpoint . TextResponseNullHandling != options . TextResponseNullHandling )
485
493
{
486
494
if ( options . LogAnnotationSetInfo )
487
495
{
488
- logger ? . CommentSetTextResponseNullHandling ( routine . Type , routine . Schema , routine . Name , words [ 1 ] ) ;
496
+ logger ? . CommentSetTextResponseNullHandling ( description , words [ 1 ] ) ;
489
497
}
490
498
}
491
499
}
@@ -509,13 +517,13 @@ internal static class DefaultCommentParser
509
517
}
510
518
else
511
519
{
512
- logger ? . InvalidQueryStringNullHandlingComment ( words [ 1 ] , routine . Schema , routine . Name , routineEndpoint . QueryStringNullHandling ) ;
520
+ logger ? . InvalidQueryStringNullHandlingComment ( words [ 1 ] , description , routineEndpoint . QueryStringNullHandling ) ;
513
521
}
514
522
if ( routineEndpoint . TextResponseNullHandling != options . TextResponseNullHandling )
515
523
{
516
524
if ( options . LogAnnotationSetInfo )
517
525
{
518
- logger ? . CommentSetQueryStringNullHandling ( routine . Type , routine . Schema , routine . Name , routineEndpoint . QueryStringNullHandling ) ;
526
+ logger ? . CommentSetQueryStringNullHandling ( description , routineEndpoint . QueryStringNullHandling ) ;
519
527
}
520
528
}
521
529
}
@@ -527,7 +535,7 @@ internal static class DefaultCommentParser
527
535
routineEndpoint . Login = true ;
528
536
if ( options . LogAnnotationSetInfo )
529
537
{
530
- logger ? . CommentSetLogin ( routine . Type , routine . Schema , routine . Name ) ;
538
+ logger ? . CommentSetLogin ( description ) ;
531
539
}
532
540
}
533
541
@@ -538,7 +546,7 @@ internal static class DefaultCommentParser
538
546
routineEndpoint . Logout = true ;
539
547
if ( options . LogAnnotationSetInfo )
540
548
{
541
- logger ? . CommentSetLogout ( routine . Type , routine . Schema , routine . Name ) ;
549
+ logger ? . CommentSetLogout ( description ) ;
542
550
}
543
551
}
544
552
@@ -554,37 +562,37 @@ internal static class DefaultCommentParser
554
562
{
555
563
if ( options . LogAnnotationSetInfo )
556
564
{
557
- logger ? . CommentBufferRows ( routine . Type , routine . Schema , routine . Name , words [ 1 ] ) ;
565
+ logger ? . CommentBufferRows ( description , words [ 1 ] ) ;
558
566
}
559
567
}
560
568
routineEndpoint . BufferRows = parsedBuffer ;
561
569
}
562
570
else
563
571
{
564
- logger ? . InvalidBufferRows ( words [ 1 ] , routine . Schema , routine . Name , options . BufferRows ) ;
572
+ logger ? . InvalidBufferRows ( words [ 1 ] , description , options . BufferRows ) ;
565
573
}
566
574
}
567
575
568
576
// raw
569
577
else if ( haveTag is true && StrEquals ( words [ 0 ] , RawKey ) )
570
578
{
571
- logger ? . CommentSetRawMode ( routine . Type , routine . Schema , routine . Name ) ;
579
+ logger ? . CommentSetRawMode ( description ) ;
572
580
routineEndpoint . Raw = true ;
573
581
}
574
582
575
583
// separator [ value ]
576
584
else if ( haveTag is true && line . StartsWith ( string . Concat ( SeparatorKey , " " ) ) )
577
585
{
578
586
var sep = line [ ( words [ 0 ] . Length + 1 ) ..] ;
579
- logger ? . CommentSetRawValueSeparator ( routine . Type , routine . Schema , routine . Name , sep ) ;
587
+ logger ? . CommentSetRawValueSeparator ( description , sep ) ;
580
588
routineEndpoint . RawValueSeparator = Regex . Unescape ( sep ) ;
581
589
}
582
590
583
591
// newline [ value ]
584
592
else if ( haveTag is true && len >= 2 && line . StartsWith ( string . Concat ( NewLineKey , " " ) ) )
585
593
{
586
594
var nl = line [ ( words [ 0 ] . Length + 1 ) ..] ;
587
- logger ? . CommentSetRawNewLineSeparator ( routine . Type , routine . Schema , routine . Name , nl ) ;
595
+ logger ? . CommentSetRawNewLineSeparator ( description , nl ) ;
588
596
routineEndpoint . RawNewLineSeparator = Regex . Unescape ( nl ) ;
589
597
}
590
598
@@ -596,7 +604,7 @@ internal static class DefaultCommentParser
596
604
routineEndpoint . RawColumnNames = true ;
597
605
if ( options . LogAnnotationSetInfo )
598
606
{
599
- logger ? . CommentRawSetColumnNames ( routine . Type , routine . Schema , routine . Name ) ;
607
+ logger ? . CommentRawSetColumnNames ( description ) ;
600
608
}
601
609
}
602
610
@@ -608,12 +616,12 @@ internal static class DefaultCommentParser
608
616
{
609
617
if ( ! ( routine . ReturnsSet == false && routine . ColumnCount == 1 && routine . ReturnsRecordType is false ) )
610
618
{
611
- logger ? . CommentInvalidParseResponse ( routine . Type , routine . Schema , routine . Name ) ;
619
+ logger ? . CommentInvalidParseResponse ( description ) ;
612
620
}
613
621
routineEndpoint . ParseResponse = true ;
614
622
if ( options . LogAnnotationSetInfo )
615
623
{
616
- logger ? . CommentParseResponse ( routine . Type , routine . Schema , routine . Name ) ;
624
+ logger ? . CommentParseResponse ( description ) ;
617
625
}
618
626
}
619
627
@@ -623,7 +631,7 @@ internal static class DefaultCommentParser
623
631
{
624
632
if ( ! ( routine . ReturnsSet == false && routine . ColumnCount == 1 && routine . ReturnsRecordType is false ) )
625
633
{
626
- logger ? . CommentInvalidCache ( routine . Type , routine . Schema , routine . Name ) ;
634
+ logger ? . CommentInvalidCache ( description ) ;
627
635
}
628
636
routineEndpoint . Cached = true ;
629
637
if ( len > 1 )
@@ -635,7 +643,7 @@ internal static class DefaultCommentParser
635
643
var name = names [ j ] ;
636
644
if ( ! routine . OriginalParamsHash . Contains ( name ) && ! routine . ParamsHash . Contains ( name ) )
637
645
{
638
- logger ? . CommentInvalidCacheParam ( routine . Type , routine . Schema , routine . Name , name ) ;
646
+ logger ? . CommentInvalidCacheParam ( description , name ) ;
639
647
} else
640
648
{
641
649
result . Add ( name ) ;
@@ -646,7 +654,7 @@ internal static class DefaultCommentParser
646
654
647
655
if ( options . LogAnnotationSetInfo )
648
656
{
649
- logger ? . CommentCached ( routine . Type , routine . Schema , routine . Name , routineEndpoint . CachedParams ?? [ ] ) ;
657
+ logger ? . CommentCached ( description , routineEndpoint . CachedParams ?? [ ] ) ;
650
658
}
651
659
}
652
660
@@ -663,12 +671,12 @@ internal static class DefaultCommentParser
663
671
routineEndpoint . CacheExpiresIn = value . Value ;
664
672
if ( options . LogAnnotationSetInfo )
665
673
{
666
- logger ? . CommentCacheExpiresIn ( routine . Type , routine . Schema , routine . Name , value . Value ) ;
674
+ logger ? . CommentCacheExpiresIn ( description , value . Value ) ;
667
675
}
668
676
}
669
677
else
670
678
{
671
- logger ? . InvalidCacheExpiresIn ( routine . Type , routine . Schema , routine . Name , string . Join ( Consts . Space , words [ 1 ..] ) ) ;
679
+ logger ? . InvalidCacheExpiresIn ( description , string . Join ( Consts . Space , words [ 1 ..] ) ) ;
672
680
}
673
681
}
674
682
@@ -683,17 +691,17 @@ internal static class DefaultCommentParser
683
691
{
684
692
if ( options . ConnectionStrings is null || options . ConnectionStrings . ContainsKey ( name ) is false )
685
693
{
686
- logger ? . CommentInvalidConnectionName ( routine . Type , routine . Schema , routine . Name , name ) ;
694
+ logger ? . CommentInvalidConnectionName ( description , name ) ;
687
695
}
688
696
routineEndpoint . ConnectionName = name ;
689
697
if ( options . LogAnnotationSetInfo )
690
698
{
691
- logger ? . CommentConnectionName ( routine . Type , routine . Schema , routine . Name , name ) ;
699
+ logger ? . CommentConnectionName ( description , name ) ;
692
700
}
693
701
}
694
702
else
695
703
{
696
- logger ? . CommentEmptyConnectionName ( routine . Type , routine . Schema , routine . Name ) ;
704
+ logger ? . CommentEmptyConnectionName ( description ) ;
697
705
}
698
706
}
699
707
@@ -716,7 +724,7 @@ internal static class DefaultCommentParser
716
724
{
717
725
if ( options . LogAnnotationSetInfo )
718
726
{
719
- logger ? . CommentSetContentType ( routine . Type , routine . Schema , routine . Name , headerValue ) ;
727
+ logger ? . CommentSetContentType ( description , headerValue ) ;
720
728
}
721
729
}
722
730
routineEndpoint . ResponseContentType = headerValue ;
@@ -745,7 +753,7 @@ internal static class DefaultCommentParser
745
753
{
746
754
if ( options . LogAnnotationSetInfo )
747
755
{
748
- logger ? . CommentSetHeader ( routine . Type , routine . Schema , routine . Name , headerName , headerValue ) ;
756
+ logger ? . CommentSetHeader ( description , headerName , headerValue ) ;
749
757
}
750
758
}
751
759
}
@@ -754,6 +762,10 @@ internal static class DefaultCommentParser
754
762
}
755
763
if ( disabled )
756
764
{
765
+ if ( options . LogAnnotationSetInfo )
766
+ {
767
+ logger ? . CommentDisabled ( description ) ;
768
+ }
757
769
return null ;
758
770
}
759
771
if ( options . CommentsMode == CommentsMode . OnlyWithHttpTag && ! hasHttpTag )
0 commit comments