-
Notifications
You must be signed in to change notification settings - Fork 91
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
Why process format if type validation fails #125
Comments
yes, this should be fixed |
I searched but didn't see a reported issue, my bad. |
Hi @whitlockjc , I put this test in place: https://github.com/zaggino/z-schema/blob/master/test/ZSchemaTestSuite/Issue125.js |
I'm not using |
Anyway, please make a PR to this test: https://github.com/zaggino/z-schema/blob/master/test/ZSchemaTestSuite/Issue125.js if you think I got it wrong somewhere. Closing this in the meantime. |
I cannot reproduce this with standalone z-schema. :) Seems my project is somehow busting things up. Not sure how but it is. |
This is really baffling. Standalone z-schema works fine, z-schema in my environment fails. If you get a few minutes: https://github.com/apigee-127/sway/blob/master/test/test-2.0.js#L303 That test, and most of the ones in that same
That shouldn't take more than a few minutes. If you see these tests pass, we have some sort of situation in my usage of z-schema where it violates the contract your new test show works in standalone z-schema. |
|
Can you make a test fail so I can check what's wrong with z-schema in your case? |
Here is a diff you can apply: diff --git a/test/test-2.0.js b/test/test-2.0.js
index 71638c8..a5c103e 100644
--- a/test/test-2.0.js
+++ b/test/test-2.0.js
@@ -314,11 +314,6 @@ describe('sway (Swagger 2.0)', function () {
code: 'INVALID_TYPE',
message: 'Expected type integer but found type number',
path: []
- },
- {
- code: 'INVALID_FORMAT',
- message: 'Object didn\'t pass validation for format int32: 1.1',
- path: []
}
]);
});
@@ -373,11 +368,6 @@ describe('sway (Swagger 2.0)', function () {
code: 'INVALID_TYPE',
message: 'Expected type integer but found type number',
path: []
- },
- {
- code: 'INVALID_FORMAT',
- message: 'Object didn\'t pass validation for format int64: 1.1',
- path: []
}
]);
});
|
Ah, error was completely in a different place, fixed in |
Glad I wasn't making it up. :) Thanks for your help. |
Hey @zaggino, Sorry to revive this, but I noticed the same behavior is introduced again, I am running v6.0.1: const ZSchema = require("z-schema");
ZSchema.registerFormat("test", (str) => {
return typeof str === 'string' && str.indexOf("https") > -1;
});
const validator = new ZSchema();
const schema = {
type: "object",
properties: {
callbacks: {
type: "array",
items: {
type: "string",
format: "test",
},
},
},
};
validator.validate(
{
callbacks: [true],
},
schema,
(data, err) => {
console.log(data);
}
); This outputs:
Is this expected in v6? Note that if I set validator.validate(
{
callbacks: ['a', 'b'],
},
schema,
(data) => {
// This now only logs 1 error
console.log(data);
}
); The above ends up in only a single validation error when
I would want:
Is this possible with v6? |
@frederikprijck Published a fix in z-schema@6.0.2 |
Confirmed, that works 👍 Thank you 🙏 |
Imagine I've got a schema like this:
I register my
int32
format validator and I validate the value1.1
. It comes to my surprise that instead of getting atype
error alone, I get atype
and aformat
error:That being said, why are we doing
format
validation on values that have failedtype
validation?The text was updated successfully, but these errors were encountered: