1.3.1 • Published 7 years ago

ajv-inspector v1.3.1

Weekly downloads
76
License
-
Repository
github
Last release
7 years ago

Build Status Coverage Status

This module allows you to inspect a JSON schema. Take a schema and request a path to drill donw into the schema to get the dereferenced schema.

This project is based on ajv and leverages it to load and compile the JSON schemas.

You don't really need this if you are not using references in your schema.

API

The first part is loading and compiling the schema, and then inspect the schema.

const SchemaInspector = require('ajv-inspector');

const schemaObject = {
  '$schema': 'http://json-schema.org/draft-04/schema#',
  type: 'object',
  title: 'Person',
  requiredProperties: ['location'],
  properties: {
    location: {'$ref': 'http://json-schema.org/geo'},
    address: {'$ref': 'http://json-schema.org/address'},
    name: {
      description: 'The person name',
      type: 'string'
    }
  }
};

// Options are passed to ajv. In this case since we have to load
// data over HTTP we can use the loader helper.
const options = {loadSchema: SchemaInspector.httpSchemaLoader};
// Build the inspector with the schema.
const inspector = new SchemaInspector(schemaObject, options);
// Compile the schema.
inspector.compile()
  .then(() => {
    // You can now inspect the schema!
    console.log(inspector.inspect('location.latitude'));
    // Outputs: {type: 'number'}
  });

See the unit tests for more details and examples.

1.3.1

7 years ago

1.3.0

7 years ago

1.2.0

7 years ago

1.1.4

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago