-
-
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
cant read multiple types in an array and cant have a property named "type" #52
Comments
Please update to the latest version which has better support for these scenarios. However, your concrete example (mixed multi type) is not currently supported out of the box. You would need to either extend createYupSchemaEntry({ schema, name, key, value, config }) {
const yupEntry = config.createYupSchemaEntry({
schema,
name,
key,
value,
config
});
return yupEntry;
} In your case the The default function is import { YupSchemaEntry } from "./entry";
function createYupSchemaEntry(opts = {}) {
// const { schema, name, key, value, config } = opts;
return new YupSchemaEntry(opts).toEntry();
} So likely you would need to extend the class The key method is toEntry In particular I would extract out the part from line 61 into a function return this.toMultiTypeEntry() || this.toSingleTypeEntry() || this.toDefaultEntry() and then implement |
Would love to see a PR for that :) |
I've just started a multi-type branch you can play with and have a look at to get a better feel for it. |
Could you please a PR with a failing spec that illustrates the problem: "I also have a property called "type" which it tries to use as the property's type" Thanks |
I've added (failing) tests for the scenarios described. |
In this case above it would result in a shape of Otherwise you would have to use |
const createValueSchema = (value, schema = yup) => {
if (value === 'string') {
return schema.string()
}
if (value === 'null') {
return schema.nullable()
}
return schema
}
let constraintListValue = ['string', 'null']
let schema = yup.mixed().test({
name,
exclusive: true,
params: {},
message: '${path} must be less than ${max} characters',
test: value => {
const schema = constraintListValue.reduce((accSchema, constraintValue) => {
return createValueSchema(constraintValue, accSchema)
}, null)
return schema.validateSync(value)
}
}); |
Latest commit includes better support for this and some better implementation suggestions for how to achieve this |
schema-to-yup - v 1.9.14
yup - 0.27.0
I have a json schema with properties of type ["string, "null"] but it cant read this properly. How do I go about adding my own custom type handler for this?
I also have a property called "type" which it tries to use as the property's type. Is there a way of getting around this too?
thanks
The text was updated successfully, but these errors were encountered: