Commit 7d860649 authored by nanahira's avatar nanahira

add allowUnknown

parent adc3c697
Pipeline #6290 passed with stages
in 23 seconds
{
"name": "koishi-utils-schemagen",
"version": "1.1.1",
"version": "1.1.2",
"description": "在 Koishi.js 中,使用类装饰器定义 Schema",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
......
......@@ -14,6 +14,7 @@ export interface SchemaClassOptions {
desc?: string;
required?: boolean;
hidden?: boolean;
allowUnknown?: boolean;
comment?: string;
default?: any;
}
......
......@@ -43,6 +43,9 @@ function applyOptionsToSchema(schema: Schema, options: SchemaClassOptions) {
if (options.comment != undefined) {
schema._comment = options.comment;
}
if (options.allowUnknown != undefined) {
schema.flag = options.allowUnknown;
}
if (options.desc != undefined) {
schema.desc = options.desc;
}
......
......@@ -41,6 +41,7 @@ console.log(JSON.stringify(schema, null, 2));
const testObject = {
a: 4,
bi: { aa: 3 },
c: ['a', 'b'],
biArr: [{ aa: 4 }, { bb: false }],
biDict: [{ cccc: { aa: 5 } }],
};
......@@ -50,6 +51,7 @@ const testObject = {
// console.log(JSON.stringify(testValidate, null, 2));
const testTransform = schemaTransform(A, testObject);
//console.log(JSON.stringify(testTransform, null, 2));
console.log(testTransform.c);
console.log(testTransform.bi instanceof B);
console.log(testTransform.biArr[0] instanceof B);
console.log(testTransform.biDict[0].cccc instanceof B);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment