github.com/youyuanwu/go-swagger@v0.19.0/cmd/swagger/commands/generate/support.go (about) 1 // Copyright 2015 go-swagger maintainers 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package generate 16 17 import ( 18 "log" 19 20 "github.com/go-swagger/go-swagger/generator" 21 ) 22 23 // Support generates the supporting files 24 type Support struct { 25 shared 26 Name string `long:"name" short:"A" description:"the name of the application, defaults to a mangled value of info.title"` 27 Operations []string `long:"operation" short:"O" description:"specify an operation to include, repeat for multiple"` 28 Principal string `long:"principal" description:"the model to use for the security principal"` 29 Models []string `long:"model" short:"M" description:"specify a model to include, repeat for multiple"` 30 DumpData bool `long:"dump-data" description:"when present dumps the json for the template generator instead of generating files"` 31 DefaultScheme string `long:"default-scheme" description:"the default scheme for this API" default:"http"` 32 } 33 34 func (s *Support) getOpts() (*generator.GenOpts, error) { 35 return &generator.GenOpts{ 36 Spec: string(s.Spec), 37 Target: string(s.Target), 38 APIPackage: s.APIPackage, 39 ModelPackage: s.ModelPackage, 40 ServerPackage: s.ServerPackage, 41 ClientPackage: s.ClientPackage, 42 Principal: s.Principal, 43 DumpData: s.DumpData, 44 DefaultScheme: s.DefaultScheme, 45 Template: s.Template, 46 TemplateDir: string(s.TemplateDir), 47 }, nil 48 } 49 50 func (s *Support) getShared() *shared { 51 return &s.shared 52 } 53 54 func (s *Support) generate(opts *generator.GenOpts) error { 55 return generator.GenerateSupport(s.Name, nil, nil, opts) 56 } 57 58 func (s *Support) log(rp string) { 59 60 log.Printf(`Generation completed! 61 62 For this generation to compile you need to have some packages in your vendor or GOPATH: 63 64 * github.com/go-openapi/runtime 65 * github.com/asaskevich/govalidator 66 * github.com/jessevdk/go-flags 67 * golang.org/x/net/context/ctxhttp 68 69 You can get these now with: go get -u -f %s/... 70 `, rp) 71 } 72 73 // Execute generates the supporting files file 74 func (s *Support) Execute(args []string) error { 75 return createSwagger(s) 76 }