github.com/thetreep/go-swagger@v0.0.0-20240223100711-35af64f14f01/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/thetreep/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( 54 `Generation completed! 55 56 For this generation to compile you need to have some packages in go.mod: 57 58 * github.com/go-openapi/runtime 59 * github.com/asaskevich/govalidator 60 * github.com/jessevdk/go-flags 61 62 You can get these now with: go mod tidy`, 63 ) 64 } 65 66 // Execute generates the supporting files file 67 func (s *Support) Execute(args []string) error { 68 return createSwagger(s) 69 }