-
Notifications
You must be signed in to change notification settings - Fork 88
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 request: map
rule
#276
Comments
Please explain it better. |
@icebob schema = {
"*": "string"
} |
Ahh, thanks. For this purpose, we use custom validators. |
@icebob I think we can introduce a new rule called const schema = {
dictionary: {
type: "map",
key: "string", // or number, default: string
value: { type: "object": props: { foo: "string" } }
}
} |
Say I have a data source that returns the current active users of a service: const status = {
timestamp: 1233113131,
numUsers: 3,
uptime: 201,
users: {
steve_carlos: {
email: 'steve.carlos@ffffff.com',
account_type: 'premium',
last_login: 11244114
},
doug_flutey: {
// same props as steve_carlos
},
mike_jones: {
// same props
}
}
} I can't write a schema to validate this object because the keys of So basically I need to validate an object much in the same was as an array is validated. For example, if |
Does |
@sbmelvin const status = {
timestamp: 1233113131,
numUsers: 3,
uptime: 201,
users: [
{
email: 'steve.carlos@ffffff.com',
name: 'steve_carlos'
account_type: 'premium',
last_login: 11244114
},
{
name: 'doug_flutey'
// same props as steve_carlos
},
{
name: 'mike_jones'
// same props
}
]
} That's the expected way of using JSON |
That is irrelevant. This is not a style guide, it's a validator. Also, what you posted is not JSON fwiw.
I'm not but that is also irrelevant. I should not have to change the structure of syntactically correct javascript in order to have it validated. My data comes from drones and remote sensors that cannot be updated once deployed. For the record, Joi and Ajv support this feature. https://joi.dev/api/?v=17.4.2#objectpatternpattern-schema-options |
Keep open, because the @erfanium |
map
rule
+1. really strange map is not here. |
@icebob As far as I know, nobody works on it. I have a similar custom rule in my project and I think I can implement it here. |
Yeah, it would be great, please open a PR with your implementation. |
Is it possible to write a schema that validates an object whose keys aren't known, but the schema of the values are?
For example:
The text was updated successfully, but these errors were encountered: