ValidationRule 验证规则
1. 结构声明
- TS Declaration
- JSON Schema
class ValidationRule extends LogicItem {
calleeNamespace: string;
calleeName: string;
arguments: Array<Argument>;
errorMessage?: LogicItem;
target?: LogicItem;
enableServerValidation?: boolean = true;
}
{
"type": "object",
"properties": {
"composedBy": {
"type": "array",
"items": {
"type": "string"
}
},
"label": {
"type": "string"
},
"description": {
"type": "string"
},
"folded": {
"type": "boolean"
},
"offsetX": {
"type": "number"
},
"offsetY": {
"type": "number"
},
"calleeNamespace": {
"type": "string"
},
"calleeName": {
"type": "string"
},
"arguments": {
"type": "array",
"items": {
"$ref": "#/definitions/Argument"
}
},
"errorMessage": {
"$ref": "#/definitions/LogicItem"
},
"target": {
"$ref": "#/definitions/LogicItem"
},
"enableServerValidation": {
"type": "boolean"
}
},
"required": [
"calleeNamespace",
"calleeName",
"arguments"
],
"additionalProperties": false
}
2. 节点示例
(1) 示例
AST 如下:
- JSON
- YAML
{
"concept": "ValidationRule",
"calleeNamespace": "nasl.validation",
"calleeName": "maxLength",
"arguments": [
{
"concept": "Argument",
"keyword": "max",
"expression": {
"concept": "NumericLiteral",
"value": "100",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Long",
"inferred": false,
"ruleMap": {}
}
}
}
],
"target": {
"concept": "Identifier",
"namespace": "",
"name": ""
},
"enableServerValidation": true
}
concept: ValidationRule
calleeNamespace: nasl.validation
calleeName: maxLength
arguments:
- concept: Argument
keyword: max
expression:
concept: NumericLiteral
value: "100"
typeAnnotation:
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: Long
inferred: false
ruleMap: {}
target:
concept: Identifier
namespace: ""
name: ""
enableServerValidation: true
对应的代码如下:
- 文本化 NASL
nasl::validation::maxLength(100)
(2) 示例
AST 如下:
- JSON
- YAML
{
"concept": "ValidationRule",
"calleeNamespace": "nasl.validation",
"calleeName": "maxLength",
"arguments": [
{
"concept": "Argument",
"keyword": "max",
"expression": {
"concept": "NumericLiteral",
"value": "100",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Long",
"inferred": false,
"ruleMap": {}
}
}
}
],
"errorMessage": {
"concept": "StringLiteral",
"value": "格式不正确"
},
"target": {
"concept": "Identifier",
"namespace": "",
"name": ""
},
"enableServerValidation": true
}
concept: ValidationRule
calleeNamespace: nasl.validation
calleeName: maxLength
arguments:
- concept: Argument
keyword: max
expression:
concept: NumericLiteral
value: "100"
typeAnnotation:
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: Long
inferred: false
ruleMap: {}
errorMessage:
concept: StringLiteral
value: 格式不正确
target:
concept: Identifier
namespace: ""
name: ""
enableServerValidation: true
对应的代码如下:
- 文本化 NASL
nasl::validation::maxLength(100)