项目原始demo,不改动
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Deze repo is gearchiveerd. U kunt bestanden bekijken en het klonen, maar niet pushen of problemen/pull-requests openen.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # json-schema-traverse
  2. Traverse JSON Schema passing each schema object to callback
  3. [![Build Status](https://travis-ci.org/epoberezkin/json-schema-traverse.svg?branch=master)](https://travis-ci.org/epoberezkin/json-schema-traverse)
  4. [![npm version](https://badge.fury.io/js/json-schema-traverse.svg)](https://www.npmjs.com/package/json-schema-traverse)
  5. [![Coverage Status](https://coveralls.io/repos/github/epoberezkin/json-schema-traverse/badge.svg?branch=master)](https://coveralls.io/github/epoberezkin/json-schema-traverse?branch=master)
  6. ## Install
  7. ```
  8. npm install json-schema-traverse
  9. ```
  10. ## Usage
  11. ```javascript
  12. const traverse = require('json-schema-traverse');
  13. const schema = {
  14. properties: {
  15. foo: {type: 'string'},
  16. bar: {type: 'integer'}
  17. }
  18. };
  19. traverse(schema, cb);
  20. // cb is called 3 times with:
  21. // 1. root schema
  22. // 2. {type: 'string'}
  23. // 3. {type: 'integer'}
  24. ```
  25. Callback function is called for each schema object (not including draft-06 boolean schemas), including the root schema. Schema references ($ref) are not resolved, they are passed as is.
  26. Callback is passed these parameters:
  27. - _schema_: the current schema object
  28. - _JSON pointer_: from the root schema to the current schema object
  29. - _root schema_: the schema passed to `traverse` object
  30. - _parent JSON pointer_: from the root schema to the parent schema object (see below)
  31. - _parent keyword_: the keyword inside which this schema appears (e.g. `properties`, `anyOf`, etc.)
  32. - _parent schema_: not necessarily parent object/array; in the example above the parent schema for `{type: 'string'}` is the root schema
  33. - _index/property_: index or property name in the array/object containing multiple schemas; in the example above for `{type: 'string'}` the property name is `'foo'`
  34. ## Traverse objects in all unknown keywords
  35. ```javascript
  36. const traverse = require('json-schema-traverse');
  37. const schema = {
  38. mySchema: {
  39. minimum: 1,
  40. maximum: 2
  41. }
  42. };
  43. traverse(schema, {allKeys: true}, cb);
  44. // cb is called 2 times with:
  45. // 1. root schema
  46. // 2. mySchema
  47. ```
  48. Without option `allKeys: true` callback will be called only with root schema.
  49. ## License
  50. [MIT](https://github.com/epoberezkin/json-schema-traverse/blob/master/LICENSE)