allow to add metas in the schema
Fix #338
I think it can be useful to add some metas in the schemas / rules
like :
dot: {
$$metas: {
openapiName: 'dot'
},
$$type: "object",
x: "number", // object props here
y: "number", // object props here
}
I think it can be usefull to reuse the validation params to do others things ( like here, generating openapi from params ) .
The keys starting with $$ can be just skipped from the validation, categorized as "system properties" ? (this can also allow to add other systems properties without breaking changes) .
I've checked with the already existing keys, to remove the metas after they are used
$$asyncseems to be used only incompile(so beforegetRuleFromSchema) / same for$$root/ seems the same for$$strict$$typeseems to be used inresolveType(ingetRuleFromSchema) only, and only on current schema ( it will callgetRuleFromSchemaonly on sub rules ), and so I removed the $$ after
I also update typescript to allow other libraries to do things like :
declare module 'fastest-validator' {
interface ValidationSchemaMetaKeys {
$$metas?: {
foo: string;
bar: string;
}
}
}
TODO :
- [ ] tests ? (the main test is to allow all other tests, without breaking them)
- [ ] do the same on a rule
I found some problems with this approach ... that I will need to investigate .
First, delete will modify schema if schema is an object (reference is keep if it's an object, so, delete will delete on the reference)
Second, it seems the schema is passed to check function . It need to be passed untouched .
So, I will need to dig more on this .
So, @icebob . I think I'm ready .
I've added tests on each rules checking if the changes doesn't impact the rule .
Also, I'm testing it when testing another library (writings examples that use this modified version), and doesn't get bugs (feel free to tag me if you found a bug on this in the future)
Also, I've found that sometimes you will handle the schemas with care, and sometimes not (like deleting $$async on source object), not sure if it's normal ?
LGTM, but could you add some sentences and example about it into the docs/README.md, please?
moreover, I should check what happened with GH actions, because CI is not executed on this PR.
@icebob is the little documentation added, ok/enough ?