Interface 接口
1. 结构声明
- TS Declaration
- JSON Schema
class Interface extends ImportedInterface {
name: string = '';
originLogicName?: string;
path: string;
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
description: string;
params: Array<InterfaceParam>;
returns: Array<Return>;
validation?: BindAttribute;
}
{
"type": "object",
"properties": {
"composedBy": {
"type": "array",
"items": {
"type": "string"
}
},
"exampleMap": {
"type": "object",
"properties": {
"size": {
"type": "number"
}
},
"required": [
"size"
],
"additionalProperties": false
},
"name": {
"type": "string"
},
"originLogicName": {
"type": "string"
},
"path": {
"type": "string"
},
"method": {
"type": "string",
"enum": [
"GET",
"POST",
"PUT",
"DELETE",
"PATCH"
]
},
"description": {
"type": "string"
},
"params": {
"type": "array",
"items": {
"$ref": "#/definitions/InterfaceParam"
}
},
"returns": {
"type": "array",
"items": {
"$ref": "#/definitions/Return"
}
},
"validation": {
"$ref": "#/definitions/BindAttribute"
}
},
"required": [
"name",
"path",
"method",
"description",
"params",
"returns"
],
"additionalProperties": false
}
2. 节点示例
(1) 示例
AST 如下:
- JSON
- YAML
{
"concept": "Interface",
"name": "phone",
"path": "/gw/getPhoneFrom/mobile/get",
"method": "GET",
"description": "",
"params": [
{
"concept": "InterfaceParam",
"name": "phone",
"description": "",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Long",
"inferred": false,
"ruleMap": {}
},
"in": "query",
"required": true
},
{
"concept": "InterfaceParam",
"name": "key",
"description": "",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "String",
"inferred": false,
"ruleMap": {}
},
"in": "query",
"required": true,
"defaultValue": {
"concept": "DefaultValue",
"expression": {
"concept": "StringLiteral",
"value": ""
},
"playground": []
}
},
{
"concept": "InterfaceParam",
"name": "type",
"description": "",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "String",
"inferred": false,
"ruleMap": {}
},
"in": "query",
"required": false,
"defaultValue": {
"concept": "DefaultValue",
"expression": {
"concept": "StringLiteral",
"value": ""
},
"playground": []
}
}
],
"returns": [
{
"concept": "Return",
"name": "result",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "reference",
"typeNamespace": "apis.getPhoneFrom.structures",
"typeName": "ApiReturnOfPhone",
"inferred": false,
"ruleMap": {}
}
}
]
}
concept: Interface
name: phone
path: /gw/getPhoneFrom/mobile/get
method: GET
description: ""
params:
- concept: InterfaceParam
name: phone
description: ""
typeAnnotation:
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: Long
inferred: false
ruleMap: {}
in: query
required: true
- concept: InterfaceParam
name: key
description: ""
typeAnnotation:
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: String
inferred: false
ruleMap: {}
in: query
required: true
defaultValue:
concept: DefaultValue
expression:
concept: StringLiteral
value: ""
playground: []
- concept: InterfaceParam
name: type
description: ""
typeAnnotation:
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: String
inferred: false
ruleMap: {}
in: query
required: false
defaultValue:
concept: DefaultValue
expression:
concept: StringLiteral
value: ""
playground: []
returns:
- concept: Return
name: result
typeAnnotation:
concept: TypeAnnotation
typeKind: reference
typeNamespace: apis.getPhoneFrom.structures
typeName: ApiReturnOfPhone
inferred: false
ruleMap: {}
对应的代码如下:
- 文本化 NASL
interface phone(
@(
description = "",
in = "query",
)
phone: Integer,
@(
description = "",
in = "query",
)
key: String = '',
@(
description = "",
in = "query",
)
type: String = '') => result: apis::getPhoneFrom::structures::ApiReturnOfPhone;