-
-
Notifications
You must be signed in to change notification settings - Fork 51
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
Question : why nullable and not type: ["null", ...] ? #162
Comments
You are absolutely right. It should be something like this: Fixing this now. nullable() {
const nullable = this.value.nullable === true || this.value.null === true;
this.base = (nullable && this.base.nullable()) || this.base;
return this;
} I've also fixed |
Please verify via the latest commit on master. Then I will publish new release |
I still can't see that array of types works
When I try to use it I get an error
|
Sorry for the last answer but it seems you've added the ability to put "age": {
"description": "Age of person",
"type": "integer",
"moreThan": 0,
"max": 130,
"default": 32,
"required": false,
"null": true
} but it's still not jsonschema compliant "age": {
"description": "Age of person",
"type": ["integer", "null"],
"moreThan": 0,
"max": 130,
"default": 32,
"required": false,
} |
Correct. This is due to MultiTypeResolver handling any type as string as a potential schema type with coresponding type handler. Null is currently not a type, but is handled by the Mixed type handler. See oneOf() {
const schemaValues = this.value
const createEntry = this.createEntry.bind(this)
const resolvedValidatorSchemas = schemaValues.map(createEntry)
return this.mixed().oneOf(resolvedValidatorSchemas)
}
notOneOf() {
const schemaValues = this.value
const createEntry = this.createEntry.bind(this)
const resolvedValidatorSchemas = schemaValues.map(createEntry)
return this.mixed().notOneOf(resolvedValidatorSchemas)
}
createEntry(value) {
const { createYupSchemaEntry } = this.config
value = normalizedValue(value)
const opts = { schema: this.schema, key: this.key, value, config: this.config }
return createYupSchemaEntry(opts)
}
normalizedValue(value) {
return typeof value === 'string' ? {type: value}: value
} A workaround would be to add an additional type handler for Which would be sth like class YupNull extends YupMixed {
// leverage existing YupMixed handling of null
} I think the above could work without any meat inside |
Working on fix here: https://github.com/kristianmandrup/schema-to-yup/tree/fix-valid-method |
@kristianmandrup any news? |
First, thanks for the helpful work.
Following the Json schema specifications, nullable fields should include "null" in their type attribute
myfield: { "type": ["number", "null"] }
https://json-schema.org/understanding-json-schema/reference/null
Is there a specific reason why the
nullable
keyword is used to describe a nullable field in this library ?The text was updated successfully, but these errors were encountered: