本文整理匯總了TypeScript中@tsed/common.JsonSchemesService.getSchemaDefinition方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript JsonSchemesService.getSchemaDefinition方法的具體用法?TypeScript JsonSchemesService.getSchemaDefinition怎麽用?TypeScript JsonSchemesService.getSchemaDefinition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@tsed/common.JsonSchemesService
的用法示例。
在下文中一共展示了JsonSchemesService.getSchemaDefinition方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: validate
/**
*
* @param obj
* @param targetType
* @param baseType
* @returns {boolean}
*/
public validate(obj: any, targetType: any, baseType?: any): boolean {
const schema = this.jsonSchemaService.getSchemaDefinition(targetType) as any;
if (schema && !(obj === null || obj === undefined)) {
const collection = baseType ? obj : [obj];
const options = {
ignoreCallback: (obj: any, type: any) => type === Date,
checkRequiredValue: false
};
const test = (obj: any) => {
const ajv = new Ajv(this.options);
const valid = ajv.validate(schema, obj);
if (!valid) {
throw this.buildErrors(ajv.errors!, targetType);
}
};
Object.keys(collection).forEach((key: any) =>
test(this.converterService.deserialize(collection[key], targetType, undefined, options))
);
}
return true;
}
示例2: it
it("should have expected json schema", () => {
expect(jsonSchemesService.getSchemaDefinition(TestDate)).to.deep.eq({
definitions: {},
properties: {
dateStart: {
format: "date-time",
type: "string"
}
},
type: "object"
});
});