• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript jsonschema.Validator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: constructor

 constructor() {
     this.validator = new Validator();
     this.validator.addSchema(signatureDataSchema as JSONSchema, signatureDataSchema.id);
     this.validator.addSchema(tokenSchema as JSONSchema, tokenSchema.id);
     this.validator.addSchema(orderTakerSchema as JSONSchema, orderTakerSchema.id);
     this.validator.addSchema(orderSchema as JSONSchema, orderSchema.id);
 }
开发者ID:NickMinnellaCS96,项目名称:website,代码行数:7,代码来源:validator.ts


示例2: getValidationErrors

export function getValidationErrors(commandKey: string, commandConfig: any, commandSchema: any): string[] {
	const validator = new Validator();
	const result = validator.validate(commandConfig, commandSchema);

	const errors = result.errors.map((err: any) => {
		let message = err.stack;
		message = message.replace(' enum ', ' expected ');
		message = message.replace('instance', `${commandKey} config`);
		return message;
	});

	return errors;
}
开发者ID:dojo,项目名称:cli,代码行数:13,代码来源:validate.ts


示例3: validate

	export function validate (element: any, schema: any) {
        let v = new Validator();
        return v.validate(element, schema);
	}
开发者ID:dsilva2401,项目名称:server-seed,代码行数:4,代码来源:validate.ts


示例4: validate

 // In order to validate a complex JS object using jsonschema, we must replace any complex
 // sub-types (e.g BigNumber) with a simpler string representation. Since BigNumber and other
 // complex types implement the `toString` method, we can stringify the object and
 // then parse it. The resultant object can then be checked using jsonschema.
 /**
  * Validate the JS object conforms to a specific JSON schema
  * @param instance JS object in question
  * @param schema Schema to check against
  * @returns The results of the validation
  */
 public validate(instance: any, schema: Schema): ValidatorResult {
     const jsonSchemaCompatibleObject = JSON.parse(JSON.stringify(instance));
     return this._validator.validate(jsonSchemaCompatibleObject, schema);
 }
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:14,代码来源:schema_validator.ts


示例5: constructor

 /**
  * Instantiates a SchemaValidator instance
  */
 constructor() {
     this._validator = new Validator();
     for (const schema of values(schemas)) {
         this._validator.addSchema(schema, schema.id);
     }
 }
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:9,代码来源:schema_validator.ts


示例6: save

function save(file: string, schema: any, data: any) {
  const result = validator.validate(data, schema);
  if (result.errors.length > 0) {
    throw result.errors;
  }
  const content = JSON.stringify(data, null, 2);
  fs.writeFileSync(file, content, "utf8");
}
开发者ID:wonderful-panda,项目名称:inazuma,代码行数:8,代码来源:persistent.ts


示例7: validateAnalysis

export function validateAnalysis(analyzedPackage: Analysis|null|undefined) {
  const result = validator.validate(analyzedPackage, schema);
  if (result.throwError) {
    throw result.throwError;
  }
  if (result.errors.length > 0) {
    throw new ValidationError(result);
  }
  if (!/^1\.\d+\.\d+$/.test(analyzedPackage!.schema_version)) {
    throw new Error(
        `Invalid schema_version in AnalyzedPackage. ` +
        `Expected 1.x.x, got ${analyzedPackage!.schema_version}`);
  }
}
开发者ID:asdfg9822,项目名称:polymer-analyzer,代码行数:14,代码来源:generate-analysis.ts


示例8: load

function load(file: string, schema: any) {
  if (!fs.existsSync(file)) {
    return undefined;
  }
  try {
    const data = fs.readFileSync(file, "utf8");
    const obj = JSON.parse(data);
    const result = validator.validate(obj, schema);
    if (result.errors.length === 0) {
      return obj;
    } else {
      console.error(`invalid JSON data found in ${name}`, result.errors);
      return undefined;
    }
  } catch (e) {
    console.error(`failed to load JSON data from ${name}`, e);
    return undefined;
  }
}
开发者ID:wonderful-panda,项目名称:inazuma,代码行数:19,代码来源:persistent.ts


示例9: addSchema

 /**
  * Add a schema to the validator. All schemas and sub-schemas must be added to
  * the validator before the `validate` and `isValid` methods can be called with
  * instances of that schema.
  * @param schema The schema to add
  */
 public addSchema(schema: Schema) {
     this._validator.addSchema(schema, schema.id);
 }
开发者ID:ewingrj,项目名称:0x-monorepo,代码行数:9,代码来源:schema_validator.ts


示例10: validate

 public validate(instance: object, schema: Schema) {
     return this.validator.validate(instance, schema);
 }
开发者ID:NickMinnellaCS96,项目名称:website,代码行数:3,代码来源:validator.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript JSONStream.parse函数代码示例发布时间:2022-05-25
下一篇:
TypeScript JSONPath.stringify函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap