forked from go-swagger/go-swagger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
swagger.go
67 lines (59 loc) · 2.38 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Copyright 2015 go-swagger maintainers
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package main
import (
"log"
"os"
"github.com/go-swagger/go-swagger/cmd/swagger/commands"
"github.com/jessevdk/go-flags"
)
var opts struct{}
func main() {
parser := flags.NewParser(&opts, flags.Default)
parser.ShortDescription = "helps you keep your API well described"
parser.LongDescription = `
Swagger tries to support you as best as possible when building API's.
It aims to represent the contract of your API with a language agnostic description of your application in json or yaml.
`
parser.AddCommand("validate", "validate the swagger document", "validate the provided swagger document against a swagger spec", &commands.ValidateSpec{})
genpar, err := parser.AddCommand("generate", "genererate go code", "generate go code for the swagger spec file", &commands.Generate{})
if err != nil {
log.Fatalln(err)
}
for _, cmd := range genpar.Commands() {
switch cmd.Name {
case "spec":
cmd.ShortDescription = "generate a swagger spec document from a go application"
cmd.LongDescription = cmd.ShortDescription
case "client":
cmd.ShortDescription = "generate all the files for a client library"
cmd.LongDescription = cmd.ShortDescription
case "server":
cmd.ShortDescription = "generate all the files for a server application"
cmd.LongDescription = cmd.ShortDescription
case "model":
cmd.ShortDescription = "generate one or more models from the swagger spec"
cmd.LongDescription = cmd.ShortDescription
case "support":
cmd.ShortDescription = "generate supporting files like the main function and the api builder"
cmd.LongDescription = cmd.ShortDescription
case "operation":
cmd.ShortDescription = "generate one or more server operations from the swagger spec"
cmd.LongDescription = cmd.ShortDescription
}
}
if _, err := parser.Parse(); err != nil {
os.Exit(1)
}
}