@@ -12,21 +12,34 @@ import (
12
12
"gopkg.in/yaml.v3"
13
13
)
14
14
15
+ // Currently supported OpenAPI types
16
+ type OpenAPIType string
17
+
18
+ const (
19
+ String OpenAPIType = "string"
20
+ Number OpenAPIType = "number"
21
+ Integer OpenAPIType = "integer"
22
+ Boolean OpenAPIType = "boolean"
23
+ )
24
+
25
+ // Metadata for all parameters
15
26
type ParamMeta struct {
16
27
Name string
17
- Type string // Same as the type name in OpenAPI
28
+ Type OpenAPIType
18
29
}
19
30
31
+ // Data passed into each handler
20
32
type HandlerData struct {
21
33
Method string // the HTTP method
22
- Path string // the parameterised path
34
+ Path string // the parameterised path. currently non interpolated
23
35
PathParams []ParamMeta // List of path params
24
36
QueryParams []ParamMeta // List of query params
25
37
HeaderParams []ParamMeta // List of header params
26
38
CookieParams []ParamMeta // List of cookie params
27
39
RequestBodyParam ParamMeta // The request body
28
40
}
29
41
42
+ // The handler signature
30
43
type Handler func (opts * cobra.Command , args []string , data HandlerData )
31
44
32
45
type extensions struct {
@@ -73,19 +86,19 @@ func addParams(cmd *cobra.Command, op *v3.Operation, handlerData *HandlerData) {
73
86
74
87
for _ , param := range op .Parameters {
75
88
schema := param .Schema .Schema ()
76
- t := "string"
89
+ t := String
77
90
if schema != nil {
78
- t = schema .Type [0 ]
91
+ t = OpenAPIType ( schema .Type [0 ])
79
92
}
80
93
81
94
switch t {
82
- case "string" :
95
+ case String :
83
96
flags .String (param .Name , "" , param .Description )
84
- case "integer" :
97
+ case Integer :
85
98
flags .Int (param .Name , 0 , param .Description )
86
- case "number" :
99
+ case Number :
87
100
flags .Float64 (param .Name , 0.0 , param .Description )
88
- case "boolean" :
101
+ case Boolean :
89
102
flags .Bool (param .Name , false , param .Description )
90
103
default :
91
104
// TODO: array, object
@@ -132,7 +145,7 @@ func addRequestBody(cmd *cobra.Command, op *v3.Operation, handlerData *HandlerDa
132
145
// TODO: Handle all the different MIME types and schemas from body.Content
133
146
// maybe assert the shape if mime is json and schema is an object
134
147
// Treats all request body content as a string as of now
135
- handlerData .RequestBodyParam = ParamMeta {Name : paramName , Type : "string" }
148
+ handlerData .RequestBodyParam = ParamMeta {Name : paramName , Type : String }
136
149
cmd .Flags ().String (paramName , "" , body .Description )
137
150
138
151
if req := body .Required ; req != nil && * req {
0 commit comments