Skip to content

Instantly share code, notes, and snippets.

@GochoMugo
Last active June 7, 2020 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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