-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsample.jsf
182 lines (137 loc) · 5.08 KB
/
sample.jsf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
grammar:
//namespace, allow 0 or more
(namespace {name_space};)
//user define class, allow 0 or more
(
(@description="{description_str}")
class {class_name}{
@jsonname={json_filed_name}(,description="{description_str}", optional=["true","false"], default="{default_value_str}")
[field_type] {field_name};
};
)
//interface, allow 1 or more
(@description="{description_str}")
Interface {interface_name}{
//request, must have only 1 for every interface
Request{
@jsonname={json_filed_name}(,description="{description_str}", optional=["true","false"], default="{default_value_str}")
[field_type] {field_name} (optional);
};
//response, must have only 1 for every interface
Response{
@jsonname={json_filed_name}(,description="{description_str}", optional=["true","false"], default="{default_value_str}")
[field_type] {field_name} (optional);
};
};
约定:
1.()表示其中的语法token是可选的,可以出现0次或1次
3.{}表示变量名
4.@表示其后是注释
5.[]表示只允许取指定集合中的值
其中:
0.{name_space}表示namespace,接受c++格式的namespace命名
1. {class_name},{interface_name},{field_name},{json_filed_name}表示自定义结构体/接口/字段名/json序列化后的字段名,可以是任何有效的变量名
2.可以通过class关键字定义0个或多个自定义结构体,必须按照使用顺序进行定义
3.可以通过Interface关键字定义1个或多个接口,每个接口中必须有且仅有1对request/response对象
4. @表示注释,目前支持jsonname,description,optional,default,含义如下:
jsonname:该字段在序列化后的字符串中的名字。[class,Interface可选,filed必填]
description:表示注释,出现在生成的C++代码中。[可选]
optional:该字段是否可选,取值为"true"或"false",默认"false"。[可选]
default:该字段的默认值。[可选]
6.[field_type] 字段类型,目前支持short, int, long, bool, unsigned, uint64_t, int64_t, double,自定义结构体,以及vector<T>。
其中T可以是其他几种支持的数据类型(包括自定义结构体)
7.本文件支持c++格式的注释,但解析时直接忽略,不会出现在生成的头文件中
示例如下:
*/
namespace jsf;
@description="地址结构体"
class Address{ //自定义结构体
@jsonname="provinceNo", description="地址编号",default="1011900"
int provinceNo;
@jsonname="provinceStr", description="省",default="上海"
string province;
@jsonname="city", description="市",default="上海"
string city;
@jsonname="town", description="区县镇",default="徐汇区"
string town;
@jsonname="address", description="详细地址",default="古美路1515弄"
string address;
};
@description="发票结构体"
class InvoiceTicket{
@jsonname="invoiceType", description="发票类型",default="28"
string invoiceType;
@jsonname="invoiceCode", description="发票代码",default="ZP1000034883232"
string invoiceCode;
@jsonname="invoiceNo", description="发票号码"
string invoiceNo;
@jsonname="amount", description="开票金额"
string amount;
@jsonname="invoiceTime", description="开票时间"
string invoiceTime;
@jsonname="state", description="状态"
string state;
@jsonname="bussinessId", description="订单号"
string bussinessId;
@jsonname="operatorCode", description="开票人"
string operatorCode;
@jsonname="operatorName", description="开票人名称"
string operatorName;
@jsonname="invoiceAddress", description="发票地址"
Address address;
@jsonname="optionalAddress", description="备选发票地址"
vector<Address> optionalAddress;
};
@description="申请开票接口 balabala...." //接口说明
Interface AddInvoice{
Request{
@jsonname="sourceId", description="来源",default="100"
int source;
@jsonname="orgId", description="开票机构",default="10009"
int organizationId;
@jsonname="ivcType",description="开票类型",default="800000"
int invoiceType;
@jsonname="reqNo", description="申请单号"
string requestNo;
@jsonname="payerNo", description="付款方识别号"
string payNo;
@jsonname="receiverNo", description="收款方识别号", optional="true" //可选字段
string receiverNo ;
@jsonname="businessIds", description="订单列表"
vector<string> bussinessIds;
@jsonname="invoiceTicket", description="发票"
InvoiceTicket invoiceTicket;
};
Response{
@jsonname="code", description="业务返回代码",default="yx"
string code;
@jsonname="msg", description="业务返回信息"
string message;
@jsonname="reqNo", description="申请单号"
string requestNo;
@jsonname="businessIds", description="订单列表", optional="true" //可选字段
vector<string> bussinessIds ;
@jsonname="invoiceTicket", description="发票"
InvoiceTicket invoiceTicket;
};
};
@description="新增商品" //接口说明
Interface AddWare{
Request(Address){
@jsonname="sourceId", description="来源",default="100"
int source;
@jsonname="receiverNo", description="收款方识别号", optional="true" //可选字段
string receiverNo ;
@jsonname="businessIds", description="订单列表"
vector<string> bussinessIds;
};
Response(Address){
@jsonname="code", description="业务返回代码",default="yy"
string code;
@jsonname="msg", description="业务返回信息"
string message;
@jsonname="reqNo", description="申请单号"
string requestNo;
};
};