-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathswagger.go
46 lines (40 loc) · 1 KB
/
swagger.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
package gomvc
import (
"log"
"github.com/spf13/cobra"
)
var swagger = &cobra.Command{
Use: "swagger",
Short: "Generate controllers from a v2 Swagger yml file",
Run: func(cmd *cobra.Command, args []string) {
configDir, err := cmd.LocalFlags().GetString("config")
if err != nil {
log.Println(err.Error())
return
}
// TODO: read spec location from config
specPath, err := cmd.LocalFlags().GetString("spec")
if err != nil {
log.Println(err.Error())
return
}
// read intended destination for generation output
destDir, err := cmd.LocalFlags().GetString("dest")
if err != nil {
log.Println(err.Error())
return
}
templateDir, err := cmd.LocalFlags().GetString("templates")
if err != nil {
log.Println(err.Error())
return
}
oa3 := LoadSwaggerV2AsV3(specPath)
GenerateFromOA(oa3, destDir, templateDir, configDir)
},
}
// Swagger is the cli command that creates a router and controller functions
// from a swagger file
func Swagger() *cobra.Command {
return swagger
}