-
Notifications
You must be signed in to change notification settings - Fork 240
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
Make schema coercion to standard data types json-compatible. #316
Comments
you could preprocess your schemas with cerberus, couldn't you? |
would it be diabolic to use the builtin callable but what doesn't make me fond of the idea is that not all types are unambious in regard to their Python counterparts. |
Well, I've just mapped all needed python types to schema type names, and this works kinda fine. The simpliest way would be to use builtins mappings for python types, I guess, but as you've said, theres inconsistency in type names, so... |
with the enhanced possible constraints that i propose in #374 the generating would be possible.
|
would an instance's configuration flag to sum up, the other proposal is to define the behaviour per field by providing either both approaches require quiet different implementations. |
there's one thing not to forget: the order in which the various normalization rules are applied matters. with the growing amount of possible alterations there's no way around the capability to configure that order per validator instance (and for some that might not be granular enough). |
I wanted this capability as well. Here is my idea: To TypeDefinition add an optional coerce field If type_coerce is true and the TypeDefinition has a coerce field, the type's coerce functions are executed after the functions in the coerce normalization rule. |
so far, there have been different proposals how to address the coercion of field's values based on the constraint which a 1. Transform a schema w/ an external functiona callable (e.g. a
turns into:
2. Set implicit coercion with a special constraint for the coerce rule per fieldthis schema:
would signal the validator that it should derive the problem with that would be, that e.g. the 3. As the previous but defined by an instance config flagthere could also be a the same problem applies here. 4. Adding a target type to
|
Unfortunately, Cerberus (our schema validation library) is not already doing this for us. So, we have a bug raised and here is the fix. We're probably open to numerous version of this bug but let's see when the reports come in. Refs: * http://docs.python-cerberus.org/en/stable/normalization-rules.html#value-coercion * pyeve/cerberus#316 Signed-off-by: Luke Murphy <[email protected]>
I've just received a bug and rolled a fix in https://github.com/ansible/molecule/pull/1798/files#diff-1e67bc3147c69bed463615849b56f3b1R683 which I think is another +1 for motivation to resolve this issue. My two cents: if I do EDIT: My solution changed a little in the end, so perhaps not exactly relevant. I had to avoid to accept values of type bool for the value I was coercing (the str coerce was converting them and that could lead to bad things). I wrote a custom coercer. |
Closes ansible#1781. Unfortunately, Cerberus (our schema validation library) is not already doing this for us. So, we have a bug raised and here is the fix. We're probably open to numerous version of this bug but let's see when the reports come in. Refs: * http://docs.python-cerberus.org/en/stable/normalization-rules.html#value-coercion * pyeve/cerberus#316 Signed-off-by: Luke Murphy <[email protected]>
Closes ansible#1781. Refs: * http://docs.python-cerberus.org/en/stable/normalization-rules.html#value-coercion * pyeve/cerberus#316 Signed-off-by: Luke Murphy <[email protected]>
Closes ansible#1781. Refs: * http://docs.python-cerberus.org/en/stable/normalization-rules.html#value-coercion * pyeve/cerberus#316 Signed-off-by: Luke Murphy <[email protected]>
Closes ansible#1781. Refs: * http://docs.python-cerberus.org/en/stable/normalization-rules.html#value-coercion * pyeve/cerberus#316 Signed-off-by: Luke Murphy <[email protected]>
Closes ansible#1781. Refs: * http://docs.python-cerberus.org/en/stable/normalization-rules.html#value-coercion * pyeve/cerberus#316 Signed-off-by: Luke Murphy <[email protected]>
Closes #1781. Refs: * http://docs.python-cerberus.org/en/stable/normalization-rules.html#value-coercion * pyeve/cerberus#316 Signed-off-by: Luke Murphy <[email protected]>
Hi.
I often use jsons for validation schemas. This helps to provide more info about the config and makes it more versatile. This usually works great with Cerberus. The problems begin when I try to use coercion to standard data types.
So it would be reasonable, as I think, to add bool or string value support for coercion to be automatically converted into a type provided in the "type" param.
Like:
or
My apologies if I missed something and it already can do this.
The text was updated successfully, but these errors were encountered: