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

'Maximum call stack size exceeded' for self-referencing allOf+not #43

Closed
whitlockjc opened this issue Jun 13, 2014 · 4 comments
Closed
Labels

Comments

@whitlockjc
Copy link
Contributor

I'm trying to get z-schema to load the Swagger Schemas. I noticed that for the modelsObject.json, I was getting a Maximum call stack size exceeded. Below is a recipe that will reproduce the issue. schemaA corresponds to dataTypeBase.json and schemaB corresponds with modelsObject.json.

var schemaA = {
  'id': 'schemaA',
  '$schema': 'http://json-schema.org/draft-04/schema#',
  'description': 'Data type fields (section 4.3.3)',
  'type': 'object',
  'oneOf': [
    { 'required': [ 'type' ] },
    { 'required': [ '$ref' ] }
  ],
  'properties': {
    'type': { 'type': 'string' },
    '$ref': { 'type': 'string' },
    'format': { 'type': 'string' },
    'defaultValue': {
      'not': { 'type': [ 'array', 'object', 'null' ] }
    },
    'enum': {
      'type': 'array',
      'items': { 'type': 'string' },
      'uniqueItems': true,
      'minItems': 1
    },
    'minimum': { 'type': 'string' },
    'maximum': { 'type': 'string' },
    'items': { '$ref': '#/definitions/itemsObject' },
    'uniqueItems': { 'type': 'boolean' }
  },
  'dependencies': {
    'format': {
      'oneOf': [
        {
          'properties': {
            'type': { 'enum': [ 'integer' ] },
            'format': { 'enum': [ 'int32', 'int64' ] }
          }
        },
        {
          'properties': {
            'type': { 'enum': [ 'number' ] },
            'format': { 'enum': [ 'float', 'double' ] }
          }
        },
        {
          'properties': {
            'type': { 'enum': [ 'string' ] },
            'format': {
              'enum': [ 'byte', 'date', 'date-time' ]
            }
          }
        }
      ]
    }
  },
  'definitions': {
    'itemsObject': {
      'oneOf': [
        {
          'type': 'object',
          'required': [ '$ref' ],
          'properties': {
            '$ref': { 'type': 'string' }
          },
          'additionalProperties': false
        },
        {
          'allOf': [
            { '$ref': '#' },
            {
              'required': [ 'type' ],
              'properties': {
                'type': {},
                'format': {}
              },
              'additionalProperties': false
            }
          ]
        }
      ]
    }
  }
};
var schemaB = {
  'id': 'schemaB',
  '$schema': 'http://json-schema.org/draft-04/schema#',
  'type': 'object',
  'required': [ 'id', 'properties' ],
  'properties': {
    'id': { 'type': 'string' },
    'description': { 'type': 'string' },
    'properties': {
      'type': 'object',
      'additionalProperties': { '$ref': '#/definitions/propertyObject' }
    },
    'subTypes': {
      'type': 'array',
      'items': { 'type': 'string' },
      'uniqueItems': true
    },
    'discriminator': { 'type': 'string' }
  },
  'dependencies': {
    'subTypes': [ 'discriminator' ]
  },
  'definitions': {
    'propertyObject': {
      'allOf': [
        {
          'not': { '$ref': '#' }
        },
        {
          '$ref': 'schemaA'
        }
      ]
    }
  }
};
var ZSchema = require('z-schema');
var validator = new ZSchema({sync: true});

try {
  validator.compileSchema([schemaA, schemaB]);
} catch (err) {
  var vError = validator.getLastError();

  if (vError && vError.valid === false) {
    console.log(validator.getLastError());
  } else {
    throw err;
  }
}
@whitlockjc
Copy link
Contributor Author

I forgot to mention that if I remove lines 107-109, it loads fine.

zaggino added a commit that referenced this issue Jun 15, 2014
@zaggino
Copy link
Owner

zaggino commented Jun 15, 2014

npm http PUT https://registry.npmjs.org/z-schema
+ z-schema@2.4.8

This issue should be fixed now, it's logged in testcase
https://github.com/zaggino/z-schema/blob/master/test/issue_43.js

@zaggino
Copy link
Owner

zaggino commented Jul 26, 2014

@whitlockjc can you please confirm this works for you and close this issue? Thanks

@whitlockjc
Copy link
Contributor Author

This seems to be fixed. Close at your convenience.

zaggino added a commit that referenced this issue Aug 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants