[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