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 types for basic meta-data annotations #335

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

remcohaszing
Copy link
Contributor

@awwright
Copy link
Collaborator

awwright commented Feb 9, 2021

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?

@remcohaszing
Copy link
Contributor Author

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.

@awwright
Copy link
Collaborator

Alright, thanks for the answer.

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

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

Successfully merging this pull request may close these issues.

2 participants