schema-has-ref

2.0.0 • Public • Published

schema-has-ref

returns whether or not a json-schema has a $ref.

supports

  • properties
  • additionalProperties
  • patternProperties
  • allOf
  • anyOf
  • oneOf
  • not
  • definitions
  • items schema
  • items array of schemas
  • additionalItems

pull requests welcome!

install

with npm, do:

npm i --save schema-has-ref

example

var schemaHasRef = require('schema-has-ref');
var _ = require('lodash');

var personSchema = {
  id: "Person",
  properties: {
    name: {
      type: "string",
    },
    resources: {
      type: 'array',
      items: {
        $ref: "Resource",
      },
    },
  },
};

var relations = _.omit(personSchema.properties, function (propSchema, propName) {
  return !schemaHasRef(propSchema);
});

console.log(JSON.stringify(relations, null, 2));
// {
//   "resources": {
//     "type": 'array',
//     "items": {
//       "$ref": "Resource"
//     }
//   }
// }

license

AGPLv3

Package Sidebar

Install

npm i schema-has-ref

Weekly Downloads

3

Version

2.0.0

License

AGPLv3

Last publish

Collaborators

  • ahdinosaur