-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdoc.go
149 lines (126 loc) · 4.7 KB
/
doc.go
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
package main
import (
"github.com/unidoc/unioffice/color"
"github.com/unidoc/unioffice/document"
"github.com/unidoc/unioffice/measurement"
"github.com/unidoc/unioffice/schema/soo/wml"
)
func requestParam(doc *document.Document, param []ReqParam) {
// request parameter list
para := doc.AddParagraph()
run := para.AddRun()
run.AddText("Request parameter list")
table := doc.AddTable()
table.Properties().SetWidthPercent(100)
borders := table.Properties().Borders()
borders.SetAll(wml.ST_BorderSingle, color.Auto, 1*measurement.Point)
hdrRow := table.AddRow()
cell := hdrRow.AddCell()
cell.Properties().SetShading(wml.ST_ShdSolid, color.LightGray, color.Auto)
cellPara := cell.AddParagraph()
cellPara.Properties().SetAlignment(wml.ST_JcLeft)
cellPara.AddRun().AddText("Parameter Name")
cell = hdrRow.AddCell()
cell.Properties().SetShading(wml.ST_ShdSolid, color.LightGray, color.Auto)
cellPara = cell.AddParagraph()
cellPara.Properties().SetAlignment(wml.ST_JcCenter)
cellPara.AddRun().AddText("Parameter Type")
cell = hdrRow.AddCell()
cell.Properties().SetShading(wml.ST_ShdSolid, color.LightGray, color.Auto)
cellPara = cell.AddParagraph()
cellPara.Properties().SetAlignment(wml.ST_JcCenter)
cellPara.AddRun().AddText("Required")
cell = hdrRow.AddCell()
cell.Properties().SetShading(wml.ST_ShdSolid, color.LightGray, color.Auto)
cellPara = cell.AddParagraph()
cellPara.Properties().SetAlignment(wml.ST_JcRight)
cellPara.AddRun().AddText("Description")
for _, v := range param {
row := table.AddRow()
row.AddCell().AddParagraph().AddRun().AddText(v.ParameterName)
row.AddCell().AddParagraph().AddRun().AddText(v.ParameterType)
row.AddCell().AddParagraph().AddRun().AddText(v.Required)
row.AddCell().AddParagraph().AddRun().AddText(v.Description)
}
}
func responseParam(doc *document.Document, param []RspParam) {
// request parameter list
para := doc.AddParagraph()
run := para.AddRun()
run.AddText("Response parameter list")
table := doc.AddTable()
table.Properties().SetWidthPercent(100)
borders := table.Properties().Borders()
borders.SetAll(wml.ST_BorderSingle, color.Auto, 1*measurement.Point)
hdrRow := table.AddRow()
cell := hdrRow.AddCell()
cell.Properties().SetShading(wml.ST_ShdSolid, color.LightGray, color.Auto)
cellPara := cell.AddParagraph()
cellPara.Properties().SetAlignment(wml.ST_JcLeft)
cellPara.AddRun().AddText("Parameter Name")
cell = hdrRow.AddCell()
cell.Properties().SetShading(wml.ST_ShdSolid, color.LightGray, color.Auto)
cellPara = cell.AddParagraph()
cellPara.Properties().SetAlignment(wml.ST_JcCenter)
cellPara.AddRun().AddText("Parameter Type")
cell = hdrRow.AddCell()
cell.Properties().SetShading(wml.ST_ShdSolid, color.LightGray, color.Auto)
cellPara = cell.AddParagraph()
cellPara.Properties().SetAlignment(wml.ST_JcRight)
cellPara.AddRun().AddText("Description")
for _, v := range param {
row := table.AddRow()
row.AddCell().AddParagraph().AddRun().AddText(v.ParameterName)
row.AddCell().AddParagraph().AddRun().AddText(v.ParameterType)
row.AddCell().AddParagraph().AddRun().AddText(v.Description)
}
}
func searchReqData(dataMap map[string]interface{}, key string) (rsp []ReqParam) {
param := dataMap["definitions"].(map[string]interface{})[key].(map[string]interface{})
for key, value := range param["properties"].(map[string]interface{}) {
var data ReqParam
data.ParameterName = key
data.ParameterType = value.(map[string]interface{})["type"].(string)
if description, ok := value.(map[string]interface{})["description"]; ok {
data.Description = description.(string)
}
if _, ok := param["required"]; !ok {
data.Required = "O"
} else {
if find(param["required"].([]interface{}), key) {
data.Required = "M"
} else {
data.Required = "O"
}
}
rsp = append(rsp, data)
}
return
}
func searchRspData(dataMap map[string]interface{}, key string, exStr string) (rsp []RspParam) {
param := dataMap["definitions"].(map[string]interface{})[key].(map[string]interface{})
for key, value := range param["properties"].(map[string]interface{}) {
var data RspParam
data.ParameterName = exStr + key
data.ParameterType = value.(map[string]interface{})["type"].(string)
if description, ok := value.(map[string]interface{})["description"]; ok {
data.Description = description.(string)
}
rsp = append(rsp, data)
// type eq array, then find object
if data.ParameterType == "array" {
arrayKey := value.(map[string]interface{})["items"].(map[string]interface{})["$ref"].(string)[14:]
arrayRsp := searchRspData(dataMap, arrayKey, "+")
rsp = append(rsp, arrayRsp...)
}
}
return
}
func find(slice []interface{}, val string) bool {
for _, item := range slice {
if item.(string) == val {
return true
}
}
return false
}