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

Handle custom validate method on fakeroot #437

Open
soumiksamanta opened this issue Aug 31, 2020 · 6 comments · Fixed by #438
Open

Handle custom validate method on fakeroot #437

soumiksamanta opened this issue Aug 31, 2020 · 6 comments · Fixed by #438

Comments

@soumiksamanta
Copy link
Contributor

Currently the Validate method called on the Go structures which are validated against the yang schema. However, there can be use cases where one need to have a custom validation which is not the part of yang schema.

Suggestion is to have a CustomValidateOptions as ValidateOptions which can be invoked in ytypes.Validate.

@soumiksamanta
Copy link
Contributor Author

@wenovus Can you please create a release? Thanks!

@wenovus
Copy link
Collaborator

wenovus commented Sep 1, 2020

Created, thanks for the change.

@robshakir
Copy link
Contributor

Re-opening for a discussion.

I wonder whether we should implement this in a bit more general manner going forward -- perhaps similarly to how cmp handles this. For example, we could have an API that is of the form:

type ValidatorFn func(interface{}) error

func WithCustomTypeValidator(t interface{}, fn ValidatorFn) { ... }

In this case, we'd compare the reflect.TypeOf each element that we are validating against the types that are registered via WithCustomTypeValidator - and fun the specified ValidatorFn -- this will mean that a user can create some custom validation against an arbitrary container, or even leaf type if they wanted to (presuming it has its own specified type).

I don't think that we need to refactor this out, but it seems like we'll end up with two APIs - and it might be a good stage to end up with a more general purpose one here in the longer-term?

@robshakir robshakir reopened this Sep 2, 2020
@wenovus
Copy link
Collaborator

wenovus commented Sep 3, 2020

Sounds reasonable to me if there is a need for it from the community.

@soumiksamanta
Copy link
Contributor Author

soumiksamanta commented Sep 3, 2020

@robshakir Yes that would be the right approach as now the CustomValidator is invoked only on the fakeroot. It would be great if the validator func can be invoked on a container at least.
Let me know if you have any specific design to fix this. I would be happy to contribute

@soumiksamanta
Copy link
Contributor Author

PR #440 is the first step for this process

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants