当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript ajv.addMetaSchema函数代码示例

本文整理汇总了TypeScript中ajv.addMetaSchema函数的典型用法代码示例。如果您正苦于以下问题:TypeScript addMetaSchema函数的具体用法?TypeScript addMetaSchema怎么用?TypeScript addMetaSchema使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了addMetaSchema函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: createConfigValidator

async function createConfigValidator() {
  const ajv = new Ajv({allErrors: true, coerceTypes: true})
  ajv.addMetaSchema(require("ajv/lib/refs/json-schema-draft-04.json"))
  require("ajv-keywords")(ajv, ["typeof"])
  const schema = await readJson(path.join(__dirname, "..", "..", "scheme.json"))
  return ajv.compile(schema)
}
开发者ID:yuya-oc,项目名称:electron-builder,代码行数:7,代码来源:config.ts

示例2: Ajv

 return fs.readJSON(path.join(respath, schemaName + ".json")).then(function (schema) {
     const ajv = new Ajv({ schemaId: 'auto', allErrors: true });
     const metaschema = require('ajv/lib/refs/json-schema-draft-04.json');
     ajv.addMetaSchema(metaschema);
     if (!ajv.validate(schema, data)) {
         throw ("JSON schema errors: " + JSON.stringify(ajv.errors, null, 2));
     }
     return data;
 })
开发者ID:crepi22,项目名称:dccjs,代码行数:9,代码来源:constants.ts

示例3: validate

export function validate(spec: Spec) {
  const ajv = new AJV({ validateSchema: true });

  /* tslint:disable */
  ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-04.json'));
  const openAPIJSONSchema = require('swagger-schema-official/schema.json');
  /* tslint:enable */

  const result = ajv.validate(openAPIJSONSchema, spec);

  return {
    valid: result,
    errors: (ajv.errors || []).slice()
  };
}
开发者ID:tyranid-org,项目名称:tyranid,代码行数:15,代码来源:utils.ts

示例4: it

  it('should be valid', () => {
    const ajv = new Ajv({
      allErrors: true,
      verbose: true,
      extendRefs: 'fail'
    });

    ajv.addMetaSchema(metaSchema);

    // now validate our data against the schema
    const valid = ajv.validateSchema(specSchema);

    if (!valid) {
      console.log(inspect(ajv.errors, {depth: 10, colors: true}));
    }
    expect(valid).toBe(true);
  });
开发者ID:vega,项目名称:vega-lite,代码行数:17,代码来源:schema.test.ts

示例5: require

// Load json schema validator
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);

开发者ID:mmeanwe,项目名称:ipywidgets,代码行数:29,代码来源:embed-webpack.ts

示例6: Ajv

import {assert} from "chai";
import {CompilerOptions} from "typescript";
import * as TJS from "../typescript-json-schema";
import {readFileSync} from "fs";
import {resolve} from "path";
import * as Ajv from "ajv";

const ajv = new Ajv();

const metaSchema = require("ajv/lib/refs/json-schema-draft-04.json");
ajv.addMetaSchema(metaSchema, "http://json-schema.org/draft-04/schema#");

const BASE = "test/programs/";

export function assertSchema(group: string, name: string, type: string, settings: TJS.PartialArgs = {}, compilerOptions?: CompilerOptions) {
    it(group + " should create correct schema", () => {
        if (!("generateRequired" in settings)) {
            settings.generateRequired = true;
        }

        const actual = TJS.generateSchema(TJS.getProgramFromFiles([resolve(BASE + group + "/" + name)], compilerOptions), type, settings);

        const file = readFileSync(BASE + group + "/schema.json", "utf8");
        const expected = JSON.parse(file);

        assert.isObject(actual);
        assert.deepEqual(actual, expected, "The schema is not as expected");

        // test against the meta schema
        if (actual !== null) {
            ajv.validateSchema(actual);
开发者ID:otgerrogla,项目名称:typescript-json-schema,代码行数:31,代码来源:schema.test.ts

示例7: require

import {compile} from '../src/compile/compile';
import * as log from '../src/log';
import {TopLevelSpec} from '../src/spec';
import {duplicate} from '../src/util';

const vlSchema = require('../build/vega-lite-schema.json');
const vgSchema = require('vega/build/vega-schema.json');

const ajv = new Ajv({
  validateSchema: true,
  allErrors: true,
  extendRefs: 'fail',
  schemaId: 'auto' // for draft 04 and 06 schemas
});

ajv.addMetaSchema(require('ajv/lib/refs/json-schema-draft-06.json'));

const validateVl = ajv.compile(vlSchema);
const validateVg = ajv.compile(vgSchema);

function validateVL(spec: TopLevelSpec) {
  const valid = validateVl(spec);
  const errors = validateVl.errors;
  if (!valid) {
    console.log(inspect(errors, {depth: 10, colors: true}));
  }

  expect(errors && errors.map((err: Ajv.ErrorObject) => err.message).join(', ')).toBeNull();
  expect(valid).toBe(true);

  expect(spec.$schema.substr(0, 42)).toBe('https://vega.github.io/schema/vega-lite/v3');
开发者ID:vega,项目名称:vega-lite,代码行数:31,代码来源:examples.test.ts

示例8: ajv

 * project root for full license information.
 *
 * @copyright Copyright (c) Nonpolynomial Labs LLC. All rights reserved.
 */

"use strict";
import {plainToClass} from "class-transformer";
import * as ajv from "ajv";
import * as Messages from "./Messages";
import { ButtplugMessageException } from "./Exceptions";
import * as buttplugSchema from "../../dependencies/buttplug-schema/schema/buttplug-schema.json";

// Since we're still using the draft 06 schema, we now have to specifically add
// it to ajv, which defaults to 7.
const validator = new ajv();
validator.addMetaSchema(require("ajv/lib/refs/json-schema-draft-06.json"));
const jsonValidator = validator.compile(buttplugSchema);

export function CheckMessage(aMsgObj: Messages.ButtplugMessage) {
  if (jsonValidator([aMsgObj.toProtocolFormat()])) {
    return;
  }
  // Relay validator errors as an error message locally.
  const errorString = jsonValidator.errors!.map((error) => error.message).join("; ");
  throw new ButtplugMessageException(errorString);
}

export function FromJSON(str): Messages.ButtplugMessage[] {
  const msgarray = JSON.parse(str);
  if (!jsonValidator(msgarray)) {
    // Relay validator errors as an error message locally.
开发者ID:metafetish,项目名称:buttplug-js,代码行数:31,代码来源:MessageUtils.ts


注:本文中的ajv.addMetaSchema函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。