@@ -508,3 +508,88 @@ func validateNamespacedName(name string) error {
508
508
}
509
509
return nil
510
510
}
511
+
512
+ // Validate validates data sources
513
+ func (ds * DataSource ) Validate () error {
514
+ if ds == nil {
515
+ return fmt .Errorf ("%w: data source is nil" , ErrValidationFailed )
516
+ }
517
+
518
+ if ds .GetName () == "" {
519
+ return fmt .Errorf ("%w: data source name cannot be empty" , ErrValidationFailed )
520
+ }
521
+
522
+ if ds .GetDriver () == nil {
523
+ return fmt .Errorf ("%w: data source driver cannot be nil" , ErrValidationFailed )
524
+ }
525
+
526
+ // All data source drivers must include validation
527
+ val , ok := ds .GetDriver ().(Validator )
528
+ if ! ok {
529
+ return fmt .Errorf ("%w: data source driver is not a valid driver" , ErrValidationFailed )
530
+ }
531
+
532
+ ds .GetRest ()
533
+
534
+ return val .Validate ()
535
+ }
536
+
537
+ // Validate is the entrypoint for the actual driver's validation
538
+ func (dsRestDriver * DataSource_Rest ) Validate () error {
539
+ if dsRestDriver == nil {
540
+ return fmt .Errorf ("%w: rest driver is nil" , ErrValidationFailed )
541
+ }
542
+
543
+ if dsRestDriver .Rest == nil {
544
+ return fmt .Errorf ("%w: rest driver is nil" , ErrValidationFailed )
545
+ }
546
+
547
+ return dsRestDriver .Rest .Validate ()
548
+ }
549
+
550
+ // Validate validates a rest data source
551
+ func (rest * RestDataSource ) Validate () error {
552
+ if rest == nil {
553
+ return fmt .Errorf ("%w: rest data source is nil" , ErrValidationFailed )
554
+ }
555
+
556
+ if len (rest .GetDef ()) == 0 {
557
+ return fmt .Errorf ("%w: rest definition is empty" , ErrValidationFailed )
558
+ }
559
+
560
+ var errs []error
561
+ for i , def := range rest .GetDef () {
562
+ if i == "" {
563
+ errs = append (errs , fmt .Errorf ("rest function name %s is empty" , i ))
564
+ }
565
+
566
+ // TODO: Should we validate valid characters here? We already do that
567
+ // in the protobuf definition.
568
+ if err := def .Validate (); err != nil {
569
+ errs = append (errs , fmt .Errorf ("rest function %s is invalid: %w" , i , err ))
570
+ }
571
+ }
572
+
573
+ if len (errs ) > 0 {
574
+ return errors .Join (errs ... )
575
+ }
576
+
577
+ return nil
578
+ }
579
+
580
+ // Validate validates a rest function
581
+ func (rest * RestDataSource_Def ) Validate () error {
582
+ if rest == nil {
583
+ return fmt .Errorf ("%w: rest function is nil" , ErrValidationFailed )
584
+ }
585
+
586
+ if rest .GetEndpoint () == "" {
587
+ return fmt .Errorf ("%w: rest function endpoint is empty" , ErrValidationFailed )
588
+ }
589
+
590
+ if rest .GetInputSchema () == nil {
591
+ return fmt .Errorf ("%w: rest function input schema is nil" , ErrValidationFailed )
592
+ }
593
+
594
+ return nil
595
+ }
0 commit comments