Skip to content
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

Option removeAdditional breaks custom keywords from 6.9.0 #955

Closed
jandolezal71 opened this issue Feb 21, 2019 · 8 comments
Closed

Option removeAdditional breaks custom keywords from 6.9.0 #955

jandolezal71 opened this issue Feb 21, 2019 · 8 comments
Labels

Comments

@jandolezal71
Copy link

Hi,

we upgraded our AJV from 6.5.0 to 6.9.0 and we are struggling with the validation error:

data: null
dataPath: ".name"
keyword: "oneOf"
message: "should match exactly one schema in oneOf"
params: {passingSchemas: [0, 1]}
passingSchemas: [0, 1]
parentSchema: {oneOf: [{$ref: "trimmedString"}, {type: "null"}]}
oneOf: [{$ref: "trimmedString"}, {type: "null"}]
schema: [{$ref: "trimmedString"}, {type: "null"}]
0: {$ref: "trimmedString"}
1: {type: "null"}

Our schema is:

export default {
	type: 'object',
	properties: {
		name: {
			oneOf: [
				{ $ref: 'trimmedString' },
				{ type: 'null' },
			],
		},
	},
	required: [ 'name' ],
};

trimmedString is keyword:

{
	type: 'string',
	minTrimmedLength: 1,
};

and minTrimmedLength is keyword:

{
	compile (minTrimmedLength) {
		return function (sample) {
			sample = sample.trim();

			return sample.length >= minTrimmedLength;
		};
	},
}

Input is:

{
  "name": null,
}

In version 6.5.0 everything works fine, but in 6.9.0 is that error. Whats wrong?

@epoberezkin
Copy link
Member

Difficult to say... Would you be able to post a code sample to runkit.com? (it's easy to run there against different versions and try changing things)

@epoberezkin
Copy link
Member

Alternatively you can try running your code against different Ajv versions to identify exactly which release caused the change.

@jandolezal71
Copy link
Author

Sure, there you go (it behave exactly as i decribed)

https://runkit.com/jandolezal71/5c6fb3cd3c877f00138f1a40

@epoberezkin
Copy link
Member

Yes, it's definitely the same issue as linked - if you remove removeAdditional it should work.

@epoberezkin
Copy link
Member

Fixing it.

@epoberezkin epoberezkin changed the title Incorrect output from new version Option removeAdditional breaks custom keywords from 6.9.0 Feb 22, 2019
@epoberezkin
Copy link
Member

as a recommendation, you may want to limit keyword to strings with "type" in definition, maybe you have it in your code.

@epoberezkin
Copy link
Member

fixed in 6.9.2

@jandolezal71
Copy link
Author

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants