github.com/josephspurrier/go-swagger@v0.2.1-0.20221129144919-1f672a142a00/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 WithShared 26 WithModels 27 WithOperations 28 29 clientOptions 30 serverOptions 31 schemeOptions 32 mediaOptions 33 34 Name string `long:"name" short:"A" description:"the name of the application, defaults to a mangled value of info.title"` 35 } 36 37 func (s *Support) apply(opts *generator.GenOpts) { 38 s.Shared.apply(opts) 39 s.Models.apply(opts) 40 s.Operations.apply(opts) 41 s.clientOptions.apply(opts) 42 s.serverOptions.apply(opts) 43 s.schemeOptions.apply(opts) 44 s.mediaOptions.apply(opts) 45 } 46 47 func (s *Support) generate(opts *generator.GenOpts) error { 48 return generator.GenerateSupport(s.Name, s.Models.Models, s.Operations.Operations, opts) 49 } 50 51 func (s Support) log(rp string) { 52 53 log.Println(`Generation completed! 54 55 For this generation to compile you need to have some packages in go.mod: 56 57 * github.com/go-openapi/runtime 58 * github.com/asaskevich/govalidator 59 * github.com/jessevdk/go-flags 60 61 You can get these now with: go mod tidy`) 62 } 63 64 // Execute generates the supporting files file 65 func (s *Support) Execute(args []string) error { 66 return createSwagger(s) 67 }