How to use the ajv/lib/refs/json-schema-draft-04.json.id function in ajv

To help you get started, we’ve selected a few ajv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stoplightio / spectral / src / functions / schema.ts View on Github external
log: console.log,
  error: console.error,
};

const ajv = new AJV({
  meta: false,
  schemaId: 'auto',
  jsonPointers: true,
  unknownFormats: 'ignore',
  logger,
});
ajv.addMetaSchema(jsonSpecv4);
ajv.addMetaSchema(jsonSpecv6);
ajv.addMetaSchema(jsonSpecv7);
// @ts-ignore
ajv._opts.defaultMeta = jsonSpecv4.id;
// @ts-ignore
ajv._refs['http://json-schema.org/schema'] = 'http://json-schema.org/draft-04/schema';

ajv.addFormat('int32', { type: 'number', validate: oasFormatValidator.int32 });
ajv.addFormat('int64', { type: 'number', validate: oasFormatValidator.int64 });
ajv.addFormat('float', { type: 'number', validate: oasFormatValidator.float });
ajv.addFormat('double', { type: 'number', validate: oasFormatValidator.double });
ajv.addFormat('byte', { type: 'string', validate: oasFormatValidator.byte });

function getSchemaId(schemaObj: JSONSchema): void | string {
  if ('$id' in schemaObj) {
    return schemaObj.$id;
  }

  if ('id' in schemaObj) {
    return schemaObj.id;
github sx1989827 / DOClever / node_modules / eslint / lib / util / ajv.js View on Github external
metaSchema = require("ajv/lib/refs/json-schema-draft-04.json");

//------------------------------------------------------------------------------
// Public Interface
//------------------------------------------------------------------------------

const ajv = new Ajv({
    meta: false,
    validateSchema: false,
    missingRefs: "ignore",
    verbose: true
});

ajv.addMetaSchema(metaSchema);
// eslint-disable-next-line no-underscore-dangle
ajv._opts.defaultMeta = metaSchema.id;

module.exports = ajv;
github cloudwan / gohan_webui / src / Form / formComponents / validator / index.js View on Github external
const ajv = new Ajv({
  meta: false,
  extendRefs: true,
  unknownFormats: 'ignore',
  allErrors: true,
  formats: {
    cidr: cidrFormat,
    mac: macFormat,
    'version-constraint': versionConstraintFormat
  }
});

// https://github.com/epoberezkin/ajv/issues/471
ajv.addMetaSchema(metaSchema);
ajv._opts.defaultMeta = metaSchema.id;
ajv._refs['http://json-schema.org/schema'] = 'http://json-schema.org/draft-04/schema';
ajv.removeKeyword('propertyNames');
ajv.removeKeyword('contains');
ajv.removeKeyword('const');

export default ajv;
github eslint / eslint / lib / shared / ajv.js View on Github external
module.exports = (additionalOptions = {}) => {
    const ajv = new Ajv({
        meta: false,
        useDefaults: true,
        validateSchema: false,
        missingRefs: "ignore",
        verbose: true,
        schemaId: "auto",
        ...additionalOptions
    });

    ajv.addMetaSchema(metaSchema);
    // eslint-disable-next-line no-underscore-dangle
    ajv._opts.defaultMeta = metaSchema.id;

    return ajv;
};
github uber / xviz / modules / schema / src / validator.js View on Github external
function newAjvDraft4() {
  const ajv = new Ajv({
    meta: false, // Prevent loading future schemas
    schemaId: 'id', // needed because we use 'id' in draft-04
    extendRefs: 'fail' // Be more strict, don't allow ref extension
  });

  const metaSchema = require('ajv/lib/refs/json-schema-draft-04.json');
  ajv.addMetaSchema(metaSchema);
  ajv._opts.defaultMeta = metaSchema.id;

  // Disable keywords defined in future drafts
  ajv.removeKeyword('propertyNames');
  ajv.removeKeyword('contains');
  ajv.removeKeyword('const');

  return ajv;
}
github openwisp / netjsonconfig-editor.js / src / js / advanced / index.js View on Github external
render({helpText, options, data, target}) {
    // code to make sure we use ajv for draft 04 schemas which we need
    const ajv = new Ajv({
      meta: false, // optional, to prevent adding draft-06 meta-schema
      extendRefs: true, // optional, current default is to 'fail'
      unknownFormats: 'ignore',  // optional, current default is true (fail)
    });
    ajv.addMetaSchema(metaSchema);
    ajv._opts.defaultMeta = metaSchema.id;
    // optional, using unversioned URI is out of spec, see https://github.com/json-schema-org/json-schema-spec/issues/216
    ajv._refs['http://json-schema.org/schema'] = 'http://json-schema.org/draft-04/schema';
    // optionally you can also disable keywords defined in draft-06
    ajv.removeKeyword('propertyNames');
    ajv.removeKeyword('contains');
    ajv.removeKeyword('const');
    // create advanced mode element with jQuery and insert into the DOM
    this.element = $('<div class="\'advanced-mode"></div>');
    this.element.appendTo($(target));
    // init editor
    this.editor = new JsonEditor(this.element[0], {...options, ajv}, data);
    this.editor.aceEditor.setOptions({
      fontSize: 14,
      showInvisibles: true,
    });
    // remove powered by ace link
github swisspush / apikana / src / validate-samples.js View on Github external
function createAjv() {
            const schemaFiles = fse.readdirSync(path.join(root, 'dist', 'model', 'json-schema-v4'));

            // verbose: Include input data information for Schema validation errors
            const ajv = new Ajv({ schemaId: 'id', verbose: true });

            logger.debug("compiling");

            const metaSchema = require('ajv/lib/refs/json-schema-draft-04.json');
            ajv.addMetaSchema(metaSchema);

            // v4 support, see https://github.com/epoberezkin/ajv/releases/tag/5.0.0
            ajv._opts.defaultMeta = metaSchema.id;

            schemaFiles.forEach(file => {
                logger.debug(`Adding schema file ${file}`);

                const fileContents = require(path.join(root, 'dist', 'model', 'json-schema-v4', file));
                fileContents.id = file; // Otherwise, $ref won't work...
                ajv.addSchema(fileContents);
            });

            return ajv;
        }
github jupyter-widgets / ipywidgets / jupyter-widgets-htmlmanager / src / embed-webpack.ts View on Github external
var Ajv = require('ajv');
var widget_state_schema = require('jupyter-widgets-schema').v2.state;
var widget_view_schema = require('jupyter-widgets-schema').v2.view;

// BEGIN: Ajv config for json-schema draft 4, from https://github.com/epoberezkin/ajv/releases/tag/5.0.0
// This can be deleted when the schema is moved to draft 6
var ajv = new Ajv({
  meta: false, // optional, to prevent adding draft-06 meta-schema
  extendRefs: true, // optional, current default is to 'fail', spec behaviour is to 'ignore'
  unknownFormats: 'ignore',  // optional, current default is true (fail)
  // ...
});

var metaSchema = require('ajv/lib/refs/json-schema-draft-04.json');
ajv.addMetaSchema(metaSchema);
ajv._opts.defaultMeta = metaSchema.id;

// optional, using unversioned URI is out of spec, see https://github.com/json-schema-org/json-schema-spec/issues/216
ajv._refs['http://json-schema.org/schema'] = 'http://json-schema.org/draft-04/schema';

// Optionally you can also disable keywords defined in draft-06
ajv.removeKeyword('propertyNames');
ajv.removeKeyword('contains');
ajv.removeKeyword('const');
// END: Ajv config for json-schema draft 4, from https://github.com/epoberezkin/ajv/releases/tag/5.0.0

let model_validate = ajv.compile(widget_state_schema);
let view_validate = ajv.compile(widget_view_schema);


// `LoadInlineWidget` is the main function called on load of the web page.
// All it does is inserting a