Structure 数据结构
1. 结构声明
- TS Declaration
- JSON Schema
class Structure extends BaseNode {
name: string = '';
description: string;
typeParams?: Array<TypeParam>;
properties: Array<StructureProperty>;
}
{
"type": "object",
"properties": {
"composedBy": {
"type": "array",
"items": {
"type": "string"
}
},
"name": {
"type": "string"
},
"description": {
"type": "string"
},
"typeParams": {
"type": "array",
"items": {
"$ref": "#/definitions/TypeParam"
}
},
"properties": {
"type": "array",
"items": {
"$ref": "#/definitions/StructureProperty"
}
}
},
"required": [
"name",
"description",
"properties"
],
"additionalProperties": false
}
2. 节点示例
(1) 示例
AST 如下:
- JSON
- YAML
{
"concept": "Structure",
"name": "ProductOrder",
"description": "",
"properties": [
{
"concept": "StructureProperty",
"name": "product",
"label": "商品",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "reference",
"typeNamespace": "app.dataSources.defaultDS.entities",
"typeName": "Product",
"inferred": false,
"ruleMap": {}
},
"jsonName": "",
"description": ""
},
{
"concept": "StructureProperty",
"name": "order",
"label": "订单",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "reference",
"typeNamespace": "app.dataSources.defaultDS.entities",
"typeName": "OrderForm",
"inferred": false,
"ruleMap": {}
},
"jsonName": "",
"description": ""
},
{
"concept": "StructureProperty",
"name": "count",
"label": "数量",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Long",
"inferred": false,
"ruleMap": {}
},
"jsonName": "",
"description": ""
}
]
}
concept: Structure
name: ProductOrder
description: ""
properties:
- concept: StructureProperty
name: product
label: 商品
typeAnnotation:
concept: TypeAnnotation
typeKind: reference
typeNamespace: app.dataSources.defaultDS.entities
typeName: Product
inferred: false
ruleMap: {}
jsonName: ""
description: ""
- concept: StructureProperty
name: order
label: 订单
typeAnnotation:
concept: TypeAnnotation
typeKind: reference
typeNamespace: app.dataSources.defaultDS.entities
typeName: OrderForm
inferred: false
ruleMap: {}
jsonName: ""
description: ""
- concept: StructureProperty
name: count
label: 数量
typeAnnotation:
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: Long
inferred: false
ruleMap: {}
jsonName: ""
description: ""
对应的代码如下:
- 文本化 NASL
@(description = "")
struct ProductOrder {
@(
label = "商品",
description = "",
jsonName = "",
)
product: app::dataSources::defaultDS::entities::Product;
@(
label = "订单",
description = "",
jsonName = "",
)
order: app::dataSources::defaultDS::entities::OrderForm;
@(
label = "数量",
description = "",
jsonName = "",
)
count: Integer;
}
(2) 带描述的示例
AST 如下:
- JSON
- YAML
{
"concept": "Structure",
"name": "ProductOrder",
"description": "表示商品订单的结构",
"properties": [
{
"concept": "StructureProperty",
"name": "product",
"label": "商品",
"description": "商品属性",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "reference",
"typeNamespace": "app.dataSources.defaultDS.entities",
"typeName": "Product",
"inferred": false,
"ruleMap": {}
},
"jsonName": "product-"
},
{
"concept": "StructureProperty",
"name": "order",
"label": "订单",
"description": "订单属性",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "reference",
"typeNamespace": "app.dataSources.defaultDS.entities",
"typeName": "OrderForm",
"inferred": false,
"ruleMap": {}
},
"jsonName": "order-"
},
{
"concept": "StructureProperty",
"name": "count",
"label": "数量",
"description": "订单中该商品的数量",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Long",
"inferred": false,
"ruleMap": {}
},
"jsonName": "count-",
"defaultValue": {
"concept": "DefaultValue",
"expression": {
"concept": "NumericLiteral",
"value": "120",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Long",
"inferred": false,
"ruleMap": {}
}
},
"playground": []
}
}
]
}
concept: Structure
name: ProductOrder
description: 表示商品订单的结构
properties:
- concept: StructureProperty
name: product
label: 商品
description: 商品属性
typeAnnotation:
concept: TypeAnnotation
typeKind: reference
typeNamespace: app.dataSources.defaultDS.entities
typeName: Product
inferred: false
ruleMap: {}
jsonName: product-
- concept: StructureProperty
name: order
label: 订单
description: 订单属性
typeAnnotation:
concept: TypeAnnotation
typeKind: reference
typeNamespace: app.dataSources.defaultDS.entities
typeName: OrderForm
inferred: false
ruleMap: {}
jsonName: order-
- concept: StructureProperty
name: count
label: 数量
description: 订单中该商品的数量
typeAnnotation:
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: Long
inferred: false
ruleMap: {}
jsonName: count-
defaultValue:
concept: DefaultValue
expression:
concept: NumericLiteral
value: "120"
typeAnnotation:
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: Long
inferred: false
ruleMap: {}
playground: []
对应的代码如下:
- 文本化 NASL
@(description = "表示商品订单的结构")
struct ProductOrder {
@(
label = "商品",
description = "商品属性",
jsonName = "product-",
)
product: app::dataSources::defaultDS::entities::Product;
@(
label = "订单",
description = "订单属性",
jsonName = "order-",
)
order: app::dataSources::defaultDS::entities::OrderForm;
@(
label = "数量",
description = "订单中该商品的数量",
jsonName = "count-",
)
count: Integer = 120;
}
(3) 示例
AST 如下:
- JSON
- YAML
{
"concept": "Structure",
"name": "ExtendedList",
"description": "",
"typeParams": [
{
"concept": "TypeParam",
"name": "T"
}
],
"properties": [
{
"concept": "StructureProperty",
"name": "length",
"typeAnnotation": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Integer",
"inferred": false,
"ruleMap": {}
},
"description": "",
"jsonName": ""
}
]
}
concept: Structure
name: ExtendedList
description: ""
typeParams:
- concept: TypeParam
name: T
properties:
- concept: StructureProperty
name: length
typeAnnotation:
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: Integer
inferred: false
ruleMap: {}
description: ""
jsonName: ""
对应的代码如下:
- 文本化 NASL
@(description = "")
struct ExtendedList<T> {
@(
description = "",
jsonName = "",
)
length: Integer;
}