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

async custom format validator does not work in oneOf #207

Open
sylar107 opened this issue May 14, 2018 · 0 comments
Open

async custom format validator does not work in oneOf #207

sylar107 opened this issue May 14, 2018 · 0 comments

Comments

@sylar107
Copy link

Problem:
async custom format validator does not get called in oneOf.

Sample test:

"use strict";

module.exports = {
  description: "async validators do not work inside oneOf",
  async: true,
  options: {
    asyncTimeout: 2000
  },
  setup: function(validator, Class) {
    // asynchronous validator
    Class.registerFormat("string-length", function(str, callback) {
      setTimeout(function() {
        callback(str.length > 10);
      }, 1);
    });

    // same as above but synchronous (comment out the validator above and try with this instead)
    // Class.registerFormat("string-length", function(str) {
    //   return str.length > 10;
    // });
  },
  schema: {
    // try removing the oneOf, starts working (allOf also works)
    oneOf: [
      {
        type: "string",
        format: "string-length"
      }
    ]

    // just these without oneOf work
    // type: "string",
    // format: "string-length"
  },
  tests: [
    {
      description:
        "should pass custom format as string length is greater than 10",
      data: "123456789012345",
      valid: true
    },
    {
      description:
        "should fail custom format as string length is lower than 10",
      data: "12345",
      valid: false
    }
  ]
};
sylar107 pushed a commit to sylar107/z-schema that referenced this issue May 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants