Strip and noUnknown
See original GitHub issueI’m trying to achieve the following.
const testSchema = yup.object().shape({
id: yup.mixed().strip(),
name: yup.string(),
}).noUnknown();
const schemaOptions = {
abortEarly: false,
strict: true,
};
test('id is stripped', t => (
testSchema.validate(
{ id: 'test', name: 'test' },
schemaOptions
).then(params => {
t.false('id' in params);
t.true('test' in params);
});
));
test('unknown keys fail', t => (
testSchema.validate(
{ unknownKey: true }
schemaOptions,
).catch(() => {
t.pass();
});
));
I can’t seem to get the test to pass, no matter what I do for schemaOptions
. Am I doing something wrong?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Unknown charge from Stripe : Stripe: Help & Support
If you see “STRIPE” on your bank statement and you're unsure which business has charged you, you can use our secure charge lookup...
Read more >How to only return the needed validated values using Yup
stripUnknown is indeed a solution. I have 2 other proposals as solution. You can use object.noUnknown. Validate that the object value only ...
Read more >unknown argument '-strip-all' (llvm-strip.exe) - Felgo
I have using the latest Felgo and NDK version. But, when try to build for android. This error occurred:
Read more >json-schema-strip-unknown - npm package - Snyk
Strips unknown values from a json-schema (forked from json-schema-filter to fix bugs) For more information about how to use this package see ...
Read more >The Unknown Comic - Comic Strip Live 1989 - YouTube
The Unknown Comic in a very funny stand up gig on Comic Strip Live in the late 80's.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
Top Related Hashnode Post
No results found
Top GitHub Comments
Ah ok so you want only the validation of
noUnknown
to run but not to actually strip those keys? You can’t have both right now using the built in validations. however you can do it with a custom validation fairly easily.I’d also take PR that splits the noUnknown method into two methods
noUnknown
andstripUnknown
for the validation and transformation respectively.you can always use two schema as well, one just for casting to your desired format