1
0
Fork 0
forked from forgejo/forgejo

[Vendor Update] go-swagger v0.20.1 -> v0.21.0 (#9410)

* Update go-swagger v0.20.1 -> v0.21.0

* go mod tidy
This commit is contained in:
6543 2019-12-18 16:05:30 +01:00 committed by Antoine GIRARD
parent 6d811bcb14
commit 90057ca27e
15 changed files with 77 additions and 65 deletions

View file

@ -37,7 +37,7 @@ type Server struct {
ExcludeSpec bool `long:"exclude-spec" description:"don't embed the swagger specification"`
WithContext bool `long:"with-context" description:"handlers get a context as first arg (deprecated)"`
DumpData bool `long:"dump-data" description:"when present dumps the json for the template generator instead of generating files"`
FlagStrategy string `long:"flag-strategy" description:"the strategy to provide flags for the server" default:"go-flags" choice:"go-flags" choice:"pflag"`
FlagStrategy string `long:"flag-strategy" description:"the strategy to provide flags for the server" default:"go-flags" choice:"go-flags" choice:"pflag" choice:"flag"`
CompatibilityMode string `long:"compatibility-mode" description:"the compatibility mode for the tls server" default:"modern" choice:"modern" choice:"intermediate"`
SkipValidation bool `long:"skip-validation" description:"skips validation of spec prior to generation"`
RegenerateConfigureAPI bool `long:"regenerate-configureapi" description:"Force regeneration of configureapi.go"`
@ -83,6 +83,7 @@ func (s *Server) getOpts() (*generator.GenOpts, error) {
FlagStrategy: s.FlagStrategy,
CompatibilityMode: s.CompatibilityMode,
ExistingModels: s.ExistingModels,
AllowTemplateOverride: s.AllowTemplateOverride,
}, nil
}
@ -98,6 +99,8 @@ func (s *Server) log(rp string) {
var flagsPackage string
if strings.HasPrefix(s.FlagStrategy, "pflag") {
flagsPackage = "github.com/spf13/pflag"
} else if strings.HasPrefix(s.FlagStrategy, "flag") {
flagsPackage = "flag"
} else {
flagsPackage = "github.com/jessevdk/go-flags"
}

View file

@ -81,6 +81,7 @@ type shared struct {
CopyrightFile flags.Filename `long:"copyright-file" short:"r" description:"copyright file used to add copyright header"`
ExistingModels string `long:"existing-models" description:"use pre-generated models e.g. github.com/foobar/model"`
AdditionalInitialisms []string `long:"additional-initialism" description:"consecutive capitals that should be considered intialisms"`
AllowTemplateOverride bool `long:"allow-template-override" description:"allows overriding protected templates"`
FlattenCmdOptions
}

View file

@ -10,6 +10,8 @@ import (
"github.com/go-openapi/loads"
"github.com/go-openapi/spec"
flags "github.com/jessevdk/go-flags"
"github.com/go-swagger/go-swagger/generator"
)
const (
@ -24,6 +26,7 @@ type MixinSpec struct {
ExpectedCollisionCount uint `short:"c" description:"expected # of rejected mixin paths, defs, etc due to existing key. Non-zero exit if does not match actual."`
Compact bool `long:"compact" description:"applies to JSON formatted specs. When present, doesn't prettify the json"`
Output flags.Filename `long:"output" short:"o" description:"the file to write to"`
KeepSpecOrder bool `long:"keep-spec-order" description:"Keep schema properties order identical to spec file"`
Format string `long:"format" description:"the format for the spec document" default:"json" choice:"yaml" choice:"json"`
}
@ -89,6 +92,9 @@ func (c *MixinSpec) MixinFiles(primaryFile string, mixinFiles []string, w io.Wri
var mixins []*spec.Swagger
for _, mixinFile := range mixinFiles {
if c.KeepSpecOrder {
mixinFile = generator.WithAutoXOrder(mixinFile)
}
mixin, lerr := loads.Spec(mixinFile)
if lerr != nil {
return nil, lerr

View file

@ -4,6 +4,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/go-openapi/spec"
"log"
"net"
"net/http"
@ -25,6 +26,7 @@ type ServeCmd struct {
DocURL string `long:"doc-url" description:"override the url which takes a url query param to render the doc ui"`
NoOpen bool `long:"no-open" description:"when present won't open the the browser to show the url"`
NoUI bool `long:"no-ui" description:"when present, only the swagger spec will be served"`
Flatten bool `long:"flatten" description:"when present, flatten the swagger spec before serving it"`
Port int `long:"port" short:"p" description:"the port to serve this site" env:"PORT"`
Host string `long:"host" description:"the interface to serve this site, defaults to 0.0.0.0" env:"HOST"`
}
@ -39,6 +41,20 @@ func (s *ServeCmd) Execute(args []string) error {
if err != nil {
return err
}
if s.Flatten {
var err error
specDoc, err = specDoc.Expanded(&spec.ExpandOptions{
SkipSchemas: false,
ContinueOnError: true,
AbsoluteCircularRef: true,
})
if err != nil {
return err
}
}
b, err := json.MarshalIndent(specDoc.Spec(), "", " ")
if err != nil {
return err

File diff suppressed because one or more lines are too long

View file

@ -41,6 +41,8 @@ func GenerateClient(name string, modelNames, operationIDs []string, opts *GenOpt
}
}
templates.SetAllowOverride(opts.AllowTemplateOverride)
if opts.TemplateDir != "" {
if err := templates.LoadDir(opts.TemplateDir); err != nil {
return err

View file

@ -55,6 +55,8 @@ func GenerateDefinition(modelNames []string, opts *GenOpts) error {
return errors.New("gen opts are required")
}
templates.SetAllowOverride(opts.AllowTemplateOverride)
if opts.TemplateDir != "" {
if err := templates.LoadDir(opts.TemplateDir); err != nil {
return err

View file

@ -63,6 +63,9 @@ func GenerateServerOperation(operationNames []string, opts *GenOpts) error {
return errors.New("gen opts are required")
}
templates.LoadDefaults()
templates.SetAllowOverride(opts.AllowTemplateOverride)
if opts.TemplateDir != "" {
if err := templates.LoadDir(opts.TemplateDir); err != nil {
return err

View file

@ -557,6 +557,7 @@ type GenOpts struct {
defaultsEnsured bool
PropertiesSpecOrder bool
StrictAdditionalProperties bool
AllowTemplateOverride bool
Spec string
APIPackage string

View file

@ -543,6 +543,11 @@ func (g *GenApp) UsePFlags() bool {
return g.GenOpts != nil && strings.HasPrefix(g.GenOpts.FlagStrategy, "pflag")
}
// UseFlags returns true when the flag strategy is set to flag
func (g *GenApp) UseFlags() bool {
return g.GenOpts != nil && strings.HasPrefix(g.GenOpts.FlagStrategy, "flag")
}
// UseIntermediateMode for https://wiki.mozilla.org/Security/Server_Side_TLS#Intermediate_compatibility_.28default.29
func (g *GenApp) UseIntermediateMode() bool {
return g.GenOpts != nil && g.GenOpts.CompatibilityMode == "intermediate"

View file

@ -70,6 +70,9 @@ func newAppGenerator(name string, modelNames, operationIDs []string, opts *GenOp
return nil, err
}
}
templates.SetAllowOverride(opts.AllowTemplateOverride)
if opts.TemplateDir != "" {
if err := templates.LoadDir(opts.TemplateDir); err != nil {
return nil, err
@ -91,7 +94,7 @@ func newAppGenerator(name string, modelNames, operationIDs []string, opts *GenOp
}
if opts.PropertiesSpecOrder {
opts.Spec = withAutoXOrder(opts.Spec)
opts.Spec = WithAutoXOrder(opts.Spec)
}
opts.Spec, specDoc, err = loadSpec(opts.Spec)
@ -178,7 +181,7 @@ type appGenerator struct {
GenOpts *GenOpts
}
func withAutoXOrder(specPath string) string {
func WithAutoXOrder(specPath string) string {
lookFor := func(ele interface{}, key string) (yaml.MapSlice, bool) {
if slice, ok := ele.(yaml.MapSlice); ok {
for _, v := range slice {

View file

@ -249,9 +249,10 @@ func NewRepository(funcs template.FuncMap) *Repository {
// Repository is the repository for the generator templates
type Repository struct {
files map[string]string
templates map[string]*template.Template
funcs template.FuncMap
files map[string]string
templates map[string]*template.Template
funcs template.FuncMap
allowOverride bool
}
// LoadDefaults will load the embedded templates
@ -329,7 +330,7 @@ func (t *Repository) addFile(name, data string, allowOverride bool) error {
}
// check if any protected templates are defined
if !allowOverride {
if !allowOverride && !t.allowOverride {
for _, template := range templ.Templates() {
if protectedTemplates[template.Name()] {
return fmt.Errorf("cannot overwrite protected template %s", template.Name())
@ -366,6 +367,11 @@ func (t *Repository) AddFile(name, data string) error {
return t.addFile(name, data, false)
}
// SetAllowOverride allows setting allowOverride after the Repository was initialized
func (t *Repository) SetAllowOverride(value bool) {
t.allowOverride = value
}
func findDependencies(n parse.Node) []string {
var deps []string