GithubHelp home page GithubHelp logo

json-schema-filter's People

Contributors

alank64 avatar ariutta avatar dorlandode avatar samuelbolduc avatar stevenluan avatar xian0831 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

json-schema-filter's Issues

Keys with null values are always omitted

Hey

I am using this module to whitelist keys that can be exposed by API. IMHO the filter should not omit key-value pairs that have null as value. As the current behavior is in place it cannot be changed. But maybe we could make a third parameter for the filter method where you could switch on/off null values omitting?
My suggestion would be to have a general property for allowing all null values. And possibility to switch separately for every type.

var result = filter(schema, document, {
  allowNulls: true
  // or
  allowNulls: ['boolean', 'number', 'integer', 'object', 'array', 'string', 'other']
})

Would it be considerable? PR?

BR

additionalProperties support

Any chance this will get additional properties support? I'm trying to use this to filter map/dictionary style responses but I'm a JS noob and have been having a hard time getting it to work with them.

GeoJSON not supported

I think there is a clash because the GeoJSON object has a object called properties.

Question: null input

What do you think of adding code to this library to check that the input is an object? Right now, the code below would throw an error:

var schema = {
    "title": "Example Schema",
    "type": "object",
    "properties": {
      "firstName": {
        "type": "string"
      }
  }
};
filter(schema, null);
filter(schema, 'mystring');

For my use case, I'm going to add code like the following before calling filter:

if (typeof input !== 'object') {
  return {}; // or maybe return null?
}

Want it in this library? Any extra checks will decrease performance, so maybe it belongs outside this library.

Keep empty strings

Right now empty strings are automatically removed. Would it be possible to keep them, as it is often useful to reset data in forms?

Thanks

Validation rules

Perhaps I'm missing something, but the example shows validation keys that I don't see anywhere in the source code: 'required', or blocks like this:

"age": { "description": "Age in years", "type": "integer", "minimum": 0 },

This Is a bit confusing to me.
Is that supposed to actually work or were there significant changes?

Support for schema URLs

I'm using tv4 for validation, and I like how it fully supports referencing schemas by URIs as per the spec. Would you be up for supporting the addSchema function from tv4?

Or is this actually supported somehow and I didn't notice?

Missing support for any type of object

JSON-SCHEMA states that if the "properties" key is missing, then any object is valid for a type: "object". A check to see if the key "properties:" is missing should be handled.

Doesn't work with booleans

Line 31, 32 and 33 of index.js are:
}else{
if (doc[key]) results[key] = doc[key];
}

since you are checking doc[key] which will result in false, it only currently works with booleans that are set to true. I have modified it to check if(doc[key] != null).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.