github.com/youyuanwu/go-swagger@v0.19.0/cmd/swagger/commands/generate/model.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 "errors" 19 "log" 20 ) 21 22 // Model the generate model file command 23 type Model struct { 24 shared 25 Name []string `long:"name" short:"n" description:"the model to generate"` 26 NoStruct bool `long:"skip-struct" description:"when present will not generate the model struct"` 27 DumpData bool `long:"dump-data" description:"when present dumps the json for the template generator instead of generating files"` 28 SkipValidation bool `long:"skip-validation" description:"skips validation of spec prior to generation"` 29 } 30 31 // Execute generates a model file 32 func (m *Model) Execute(args []string) error { 33 34 if m.DumpData && len(m.Name) > 1 { 35 return errors.New("only 1 model at a time is supported for dumping data") 36 } 37 38 if m.ExistingModels != "" { 39 log.Println("warning: Ignoring existing-models flag when generating models.") 40 } 41 s := &Server{ 42 shared: m.shared, 43 Models: m.Name, 44 DumpData: m.DumpData, 45 ExcludeMain: true, 46 ExcludeSpec: true, 47 SkipSupport: true, 48 SkipOperations: true, 49 SkipModels: m.NoStruct, 50 SkipValidation: m.SkipValidation, 51 } 52 return s.Execute(args) 53 }