當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript jsonschema.Validator類代碼示例

本文整理匯總了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;未經允許,請勿轉載。