Skip to content

Commit 570f193

Browse files
committed
feat: swaggmaan cmd: add XSLX output option
1 parent 3823928 commit 570f193

File tree

1 file changed

+35
-24
lines changed

1 file changed

+35
-24
lines changed

swaggman.go

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ import (
1414
// Convert yaml2json: https://github.com/bronze1man/yaml2json ... yaml2json_darwin_amd64
1515

1616
type Options struct {
17+
OpenAPIFile string `short:"O" long:"openapiFile" description:"Input Swagger File" required:"true"`
1718
Config string `short:"C" long:"config" description:"Swaggman Config File"`
1819
PostmanBase string `short:"B" long:"basePostmanFile" description:"Basic Postman File"`
19-
Postman string `short:"P" long:"postmanFile" description:"Output Postman File" required:"true"`
20-
OpenAPIFile string `short:"O" long:"openapiFile" description:"Input Swagger File" required:"true"`
20+
Postman string `short:"P" long:"postmanFile" description:"Output Postman File"`
21+
XLSXFile string `short:"X" long:"xlsxFile" description:"Output XLSX File"`
2122
}
2223

2324
func (opts *Options) TrimSpace() {
@@ -34,34 +35,44 @@ func main() {
3435
log.Fatal(err)
3536
}
3637

37-
cfg3 := openapi3postman2.Configuration{}
38-
39-
if len(opts.Config) > 0 {
40-
cfg3, err = openapi3postman2.ConfigurationReadFile(opts.Config)
41-
if err != nil {
42-
errors.Wrap(err, "openapi3postman2.ConfigurationReadFile")
43-
log.Fatal(err)
44-
}
45-
}
46-
4738
spec, err := openapi3.ReadFile(opts.OpenAPIFile, true)
4839
if err != nil {
4940
log.Fatal(err)
5041
}
51-
conv := openapi3postman2.Converter{
52-
Configuration: cfg3,
53-
OpenAPISpec: spec}
5442

55-
err = conv.MergeConvert(
56-
opts.OpenAPIFile,
57-
opts.PostmanBase,
58-
opts.Postman)
43+
if len(opts.Postman) > 0 {
44+
cfg3 := openapi3postman2.Configuration{}
5945

60-
if err != nil {
61-
errors.Wrap(err, "swaggman.main << conv.MergeConvert")
62-
log.Fatal(err)
63-
}
46+
if len(opts.Config) > 0 {
47+
cfg3, err = openapi3postman2.ConfigurationReadFile(opts.Config)
48+
if err != nil {
49+
errors.Wrap(err, "openapi3postman2.ConfigurationReadFile")
50+
log.Fatal(err)
51+
}
52+
}
6453

65-
fmt.Printf("wrote Postman collection [%s]\n", opts.Postman)
54+
conv := openapi3postman2.Converter{
55+
Configuration: cfg3,
56+
OpenAPISpec: spec}
57+
58+
err = conv.MergeConvert(
59+
opts.OpenAPIFile,
60+
opts.PostmanBase,
61+
opts.Postman)
62+
63+
if err != nil {
64+
errors.Wrap(err, "swaggman.main << conv.MergeConvert")
65+
log.Fatal(err)
66+
}
67+
68+
fmt.Printf("wrote Postman collection [%s]\n", opts.Postman)
69+
}
70+
if len(opts.XLSXFile) > 0 {
71+
sm := openapi3.SpecMore{Spec: spec}
72+
err := sm.WriteFileXLSX(opts.XLSXFile, nil, nil)
73+
if err != nil {
74+
log.Fatal(err)
75+
}
76+
}
6677
fmt.Println("DONE")
6778
}

0 commit comments

Comments
 (0)