Skip to content

Instantly share code, notes, and snippets.

@GochoMugo
Last active June 7, 2020 09:57
Show Gist options
  • Save GochoMugo/ee1363ca2274743ca612d2393819a723 to your computer and use it in GitHub Desktop.
Save GochoMugo/ee1363ca2274743ca612d2393819a723 to your computer and use it in GitHub Desktop.
Ajv issue - IPv4 address satisfies 'hostname' format (https://github.com/ajv-validator/ajv/issues/832)
var Ajv = require("ajv");
ajv = new Ajv({
});
var schema = {
"type": "object",
"properties": {
"host": {
"type": "string",
"oneOf": [
{ "format": "hostname" },
{ "format": "ipv4" }
]
}
}
};
var data = {
"host": "127.0.0.1"
};
var validate = ajv.compile(schema);
console.log(validate(data));
console.log(validate.errors);
{
"dependencies": {
"ajv": "6.5.2"
}
}
false
[ { keyword: 'oneOf',
dataPath: '.host',
schemaPath: '#/properties/host/oneOf',
params: { passingSchemas: [Array] },
message: 'should match exactly one schema in oneOf' } ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment