Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature]: Custom validation for dashboard builder #390

Open
olehholovko-stripe opened this issue Nov 27, 2024 · 1 comment
Open

[Feature]: Custom validation for dashboard builder #390

olehholovko-stripe opened this issue Nov 27, 2024 · 1 comment
Assignees
Labels
question Further information is requested

Comments

@olehholovko-stripe
Copy link

Why is this needed?

Hi!

I was looking into the Go version of the SDK and noticed that DashboardBuilder.internal property is private. I was thinking about adding custom validations for the resulting dashboard. The easiest solution was to leverage SDK's structs but then implement a custom function to accept DashboardBuilder and run the validation, something along the lines of:

func ValidateDashboard(d *dashboard.DashboardBuilder) error {
    if d.Internal().Title == "" {
           return fmt.Errorf("empty title")
    }
}

I noticed that in TypeScript the internal property of the DashboardBuilder is protected readonly which allows users to extend the class and access internal field for any custom validation:

class ValidatedDashboardBuilder extends dashboard.DashboardBuilder {
    constructor(title: string) {
        super(title);
    }

    validate(): boolean {
        if (!this.internal.title) {
            console.error("Dashboard title is required.");
            return false;
        }
        return true;
    }
}

What would you like to be added?

Is it possible to generate a getter for the internal field of the dashboard.DashboardBuilder in Go please? Alternatively, a user can provide an additional custom validation function that the Build can run.

@olehholovko-stripe olehholovko-stripe added the enhancement New feature or request label Nov 27, 2024
@K-Phoen K-Phoen self-assigned this Jan 10, 2025
@K-Phoen
Copy link
Member

K-Phoen commented Jan 10, 2025

Hey there!

Haven't given too much thought to this (yet), but why not running the validation directly on the models instead of the builders?

func ValidateDashboard(d *dashboard.Dashboard) error {
  if d.Title == "" {
    return fmt.Errorf("empty title")
  }

  return nil
}

@K-Phoen K-Phoen added question Further information is requested and removed enhancement New feature or request labels Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants