jsonschema icon indicating copy to clipboard operation
jsonschema copied to clipboard

Add types for basic meta-data annotations

Open remcohaszing opened this issue 4 years ago • 3 comments

The types were determined from https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.9

remcohaszing avatar Feb 09 '21 16:02 remcohaszing

This library doesn't actually use these properties for anything, however. Is there a particular benefit to listing properties that don't affect the behavior?

awwright avatar Feb 09 '21 17:02 awwright

This library might not use these properties directly, but it does implement a specification that defines them.

Some functions specify a schema is passed to a callback. This schema should be a valid JSON schema, it shouldn’t just specify the properties consumed internally.

For example:

import { Schema, Validator } from 'jsonschema';

const schema: Schema = {
  type: 'object',
  properties: {
    string: {
      type: 'string',
      // This should be ok
      default: 'Hello'
    }
  },
};

const v = new Validator();
const res = v.validate(value, schema, {
  rewrite(instance, schema) {
    if (instance === undefined) {
      // This should be ok
      return schema.default;
    }
    return instance;
  }
});

I can think of similar use cases for the other properties I added.

Besides that I also like the simplicity of the existing Schema type in this package and I’m using it on other places, since I’m already depending on this package anyway.

remcohaszing avatar Feb 09 '21 17:02 remcohaszing

Alright, thanks for the answer.

At the very least, how about I work this in to #318

awwright avatar Feb 10 '21 01:02 awwright