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

add schema.examples (new in draft 6) #353

Open
kussmaul opened this issue Oct 16, 2021 · 0 comments
Open

add schema.examples (new in draft 6) #353

kussmaul opened this issue Oct 16, 2021 · 0 comments

Comments

@kussmaul
Copy link

JSON Schema draft 6 adds an examples array "to provide an array of examples that validate against the schema":
https://json-schema.org/understanding-json-schema/reference/generic.html#annotations

Please add Schema.examples, and perhaps validateExamples(schema) to validate each example against the schema, similar to this code from my Jasmine tests.

  type      Schema    = JsonSchema.Schema // & { examples : [] };
  let       Validator = require('jsonschema').Validator;
  let       validator = new Validator();
  function  validateExamples(schema : Schema) {
    (schema as any).examples.map((e : any) => {
      const result = validator.validate(e, schema);
      expect(result.errors).toEqual([]);
      if (result.errors.length) { console.log('validate()', e, result); }
    });
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant