-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerateparameter.go
More file actions
38 lines (33 loc) · 862 Bytes
/
generateparameter.go
File metadata and controls
38 lines (33 loc) · 862 Bytes
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
package swaggeneration
import (
"gopkg.in/yaml.v2"
)
type parameter struct {
InType string `yaml:"in,omitempty"`
Name string `yaml:"name,omitempty"`
Schema *property `yaml:"schema,omitempty"`
IsRequired bool `yaml:"required,omitempty"`
}
func generateHeaderSchemaFromAllExample(example map[interface{}]interface{}) string {
uniqueKeyBody := map[string]parameter{}
for _, e := range example {
entry := e.(map[interface{}]interface{})
headerList := entry["requestHeader"].(map[string]string)
for key, i := range headerList {
uniqueKeyBody[key] = parameter{
InType: "header",
Name: key,
Schema: &property{
DataType: "string",
Example: i,
},
IsRequired: false, // TODO
}
}
}
yamlData, err := yaml.Marshal(uniqueKeyBody)
if err != nil {
panic(err)
}
return string(yamlData)
}