Enum 枚举
1. 结构声明
- TS Declaration
- JSON Schema
class Enum extends BaseNode {
name: string = '';
label?: string;
description?: string;
enumItems: Array<EnumItem>;
valueType: TypeAnnotation;
}
{
"type": "object",
"properties": {
"composedBy": {
"type": "array",
"items": {
"type": "string"
}
},
"changedTime": {
"$ref": "#/definitions/long"
},
"name": {
"type": "string"
},
"label": {
"type": "string"
},
"description": {
"type": "string"
},
"enumItems": {
"type": "array",
"items": {
"$ref": "#/definitions/EnumItem"
}
},
"valueType": {
"$ref": "#/definitions/TypeAnnotation"
}
},
"required": [
"name",
"enumItems",
"valueType"
],
"additionalProperties": false
}
2. 节点示例
(1) 示例
AST 如下:
- JSON
- YAML
{
"concept": "Enum",
"name": "ProductStatus",
"label": "",
"description": "",
"valueType": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "String",
"inferred": false,
"ruleMap": {}
},
"enumItems": [
{
"concept": "EnumItem",
"value": "Listing",
"label": {
"concept": "StaticString",
"value": "上架"
}
},
{
"concept": "EnumItem",
"value": "Delisting",
"label": {
"concept": "StaticString",
"value": "下架"
}
}
]
}
concept: Enum
name: ProductStatus
label: ""
description: ""
valueType:
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: String
inferred: false
ruleMap: {}
enumItems:
- concept: EnumItem
value: Listing
label:
concept: StaticString
value: 上架
- concept: EnumItem
value: Delisting
label:
concept: StaticString
value: 下架
对应的代码如下:
- 文本化 NASL
- Natural TS
@(
label = "",
description = "",
)
enum ProductStatus {
@(label = '上架')
case Listing;
@(label = '下架')
case Delisting;
}
enum ProductStatus {
'Listing' = '上架',
'Delisting' = '下架',
}
(2) 带描述的示例
AST 如下:
- JSON
- YAML
{
"concept": "Enum",
"name": "ProductStatus",
"label": "商品状态",
"description": "表示商品状态的枚举",
"valueType": {
"concept": "TypeAnnotation",
"typeKind": "primitive",
"typeNamespace": "nasl.core",
"typeName": "Long",
"inferred": false,
"ruleMap": {}
},
"enumItems": [
{
"concept": "EnumItem",
"value": "Listing",
"label": {
"concept": "StaticString",
"value": "上架"
}
},
{
"concept": "EnumItem",
"value": "Delisting",
"label": {
"concept": "StaticString",
"value": "下架"
}
}
]
}
concept: Enum
name: ProductStatus
label: 商品状态
description: 表示商品状态的枚举
valueType:
concept: TypeAnnotation
typeKind: primitive
typeNamespace: nasl.core
typeName: Long
inferred: false
ruleMap: {}
enumItems:
- concept: EnumItem
value: Listing
label:
concept: StaticString
value: 上架
- concept: EnumItem
value: Delisting
label:
concept: StaticString
value: 下架
对应的代码如下:
- 文本化 NASL
- Natural TS
@(
label = "商品状态",
description = "表示商品状态的枚举",
)
enum ProductStatus {
@(label = '上架')
case Listing;
@(label = '下架')
case Delisting;
}
enum ProductStatus {
'Listing' = '上架',
'Delisting' = '下架',
}