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

standardize validator functions to all Object props #8903

Open
indirectlylit opened this issue Dec 13, 2021 · 13 comments
Open

standardize validator functions to all Object props #8903

indirectlylit opened this issue Dec 13, 2021 · 13 comments
Assignees
Labels
help wanted Open source contributors welcome

Comments

@indirectlylit
Copy link
Contributor

Observed behavior

Following up from: #8640, #8878, and #8902 which added validation functions.

There are a large number of Object-type props with no validator function. (Search the codebase using a multi-line regex to help find them: {[^}]*type: Object[^}]*})

Normal component props are well-documented using type, required, and sometimes validator. The keys of Object props are as much a part of the component API as the other ones, but they are often under-documented.

Even when validation of Object props is done in Kolibri, it is performed in an ad-hoc manner with little consistency and the logging is less useful because usually Vue will simply say the validator failed without specifying why. Some examples:

device: {
type: Object,
required: true,
validator(val) {
return val.name && val.id && val.baseurl;
},
},

device: {
type: Object,
required: true,
validator(val) {
return isString(val.name) && isString(val.id) && isString(val.baseurl);
},
},

value: {
type: Object,
required: true,
validator(value) {
const inputKeys = ['channels', 'accessibility_labels', 'languages', 'grade_levels'];
return inputKeys.every(k => Object.prototype.hasOwnProperty.call(value, k));
},
},

Expected behavior

Component object props should have a validator and fill in default values which should simplify internal logic of components using these props

@nikkuAg
Copy link
Contributor

nikkuAg commented Feb 9, 2024

Is this issue still open? I would like to work on this

@MisRob
Copy link
Member

MisRob commented Feb 12, 2024

Hi, @nikkuAg, yes, thanks for volunteering

@indirectlylit
Copy link
Contributor Author

This seems to be relevant

yes, that was the intent - thank you

Introduces two new functions, validateObject and objectWithDefaults, which bring Vue prop-like validation and default behavior to nested javascript objects. This can be used with component props, vuex and API validation, and other scenarios

a stopgap for lack of TypeScript, perhaps :)

@rtibbles
Copy link
Member

a stopgap for lack of TypeScript

Except we could use this for runtime validation, which TypeScript does not provide!

@nikkuAg
Copy link
Contributor

nikkuAg commented Mar 1, 2024

Hi,
I am not entirely able to understand what I have to do.

@rtibbles
Copy link
Member

rtibbles commented Mar 4, 2024

The basic idea is to use the Object validation specification work that was done in the referenced PRs, and use it to fully document each of the cases where an Object type is used as a prop.

This allows for better specification of the intended properties and shape of the prop, and to give more semantic error messages when these expectations are violated.

I would start by looking at one of the examples listed in the issue, and replacing the validator function with the Object validation specification.

@MisRob
Copy link
Member

MisRob commented Apr 5, 2024

Hi @nikkuAg, are you still planning to work on this at some point or would it be better to unassign?

@nikkuAg
Copy link
Contributor

nikkuAg commented Apr 7, 2024

Hi @MisRob,
I'm currently occupied with another task, but once I complete it, I'll be able to pick this up. Therefore, I believe it would be best to unassign me for now so that someone else can take over.

@MisRob
Copy link
Member

MisRob commented Apr 8, 2024

Okay @nikkuAg, thank you, let us know any time if you'd like to return to this

@tiffcoding
Copy link

hello, can i be assigned to work on a few of these validators?

@rtibbles
Copy link
Member

rtibbles commented Dec 9, 2024

Hi @tiffcoding - yes, and please do feel free to open a PR with just a few of them, there is no need to do all of these all at once!

@MisRob
Copy link
Member

MisRob commented Dec 17, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Open source contributors welcome
Projects
None yet
Development

No branches or pull requests

6 participants