diff --git a/analysis_test/spec_test.go b/analysis_test/spec_test.go index b7c44c3..4aa2a0b 100644 --- a/analysis_test/spec_test.go +++ b/analysis_test/spec_test.go @@ -11,7 +11,7 @@ import ( "github.com/go-openapi/analysis/internal/antest" "github.com/go-openapi/loads" "github.com/go-openapi/spec" - "github.com/go-openapi/swag" + "github.com/go-openapi/swag/loading" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -29,7 +29,7 @@ func Test_FlattenAzure(t *testing.T) { // Local copy of https://raw.githubusercontent.com/Azure/azure-rest-api-specs/master/specification/network/resource-manager/Microsoft.Network/stable/2020-04-01/publicIpAddress.json url := "../fixtures/azure/publicIpAddress.json" - byts, err := swag.LoadFromFileOrHTTP(url) + byts, err := loading.LoadFromFileOrHTTP(url) assert.NoError(t, err) swagger := &spec.Swagger{} require.NoError(t, swagger.UnmarshalJSON(byts)) diff --git a/analyzer.go b/analyzer.go index daa23ae..6b0147e 100644 --- a/analyzer.go +++ b/analyzer.go @@ -22,7 +22,7 @@ import ( "github.com/go-openapi/jsonpointer" "github.com/go-openapi/spec" - "github.com/go-openapi/swag" + "github.com/go-openapi/swag/mangling" ) const ( @@ -307,8 +307,9 @@ func fieldNameFromParam(param *spec.Parameter) string { if nm, ok := param.Extensions.GetString("go-name"); ok { return nm } + mangler := mangling.NewNameMangler() - return swag.ToGoName(param.Name) + return mangler.ToGoName(param.Name) } // ErrorOnParamFunc is a callback function to be invoked diff --git a/flatten_name.go b/flatten_name.go index d197b5d..44ffe42 100644 --- a/flatten_name.go +++ b/flatten_name.go @@ -11,7 +11,7 @@ import ( "github.com/go-openapi/analysis/internal/flatten/schutils" "github.com/go-openapi/analysis/internal/flatten/sortref" "github.com/go-openapi/spec" - "github.com/go-openapi/swag" + "github.com/go-openapi/swag/mangling" ) // InlineSchemaNamer finds a new name for an inlined type @@ -270,8 +270,9 @@ func mangler(o *FlattenOpts) func(string) string { if o.KeepNames { return func(in string) string { return in } } + mangler := mangling.NewNameMangler() - return swag.ToJSONName + return mangler.ToJSONName } func nameFromRef(ref spec.Ref, o *FlattenOpts) string { diff --git a/go.mod b/go.mod index cdf9589..d0f0d6f 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,9 @@ require ( github.com/go-openapi/jsonpointer v0.21.2 github.com/go-openapi/spec v0.21.0 github.com/go-openapi/strfmt v0.23.0 - github.com/go-openapi/swag v0.23.1 + github.com/go-openapi/swag/jsonutils v0.24.0 + github.com/go-openapi/swag/loading v0.24.0 + github.com/go-openapi/swag/mangling v0.24.0 github.com/stretchr/testify v1.11.1 ) @@ -13,6 +15,15 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/go-openapi/errors v0.22.0 // indirect github.com/go-openapi/jsonreference v0.21.0 // indirect + github.com/go-openapi/swag v0.24.1 // indirect + github.com/go-openapi/swag/cmdutils v0.24.0 // indirect + github.com/go-openapi/swag/conv v0.24.0 // indirect + github.com/go-openapi/swag/fileutils v0.24.0 // indirect + github.com/go-openapi/swag/jsonname v0.24.0 // indirect + github.com/go-openapi/swag/netutils v0.24.0 // indirect + github.com/go-openapi/swag/stringutils v0.24.0 // indirect + github.com/go-openapi/swag/typeutils v0.24.0 // indirect + github.com/go-openapi/swag/yamlutils v0.24.0 // indirect github.com/google/uuid v1.6.0 // indirect github.com/josharian/intern v1.0.0 // indirect github.com/mailru/easyjson v0.9.0 // indirect diff --git a/go.sum b/go.sum index 1ab65f5..6f2e543 100644 --- a/go.sum +++ b/go.sum @@ -12,8 +12,30 @@ github.com/go-openapi/spec v0.21.0 h1:LTVzPc3p/RzRnkQqLRndbAzjY0d0BCL72A6j3CdL9Z github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk= github.com/go-openapi/strfmt v0.23.0 h1:nlUS6BCqcnAk0pyhi9Y+kdDVZdZMHfEKQiS4HaMgO/c= github.com/go-openapi/strfmt v0.23.0/go.mod h1:NrtIpfKtWIygRkKVsxh7XQMDQW5HKQl6S5ik2elW+K4= -github.com/go-openapi/swag v0.23.1 h1:lpsStH0n2ittzTnbaSloVZLuB5+fvSY/+hnagBjSNZU= -github.com/go-openapi/swag v0.23.1/go.mod h1:STZs8TbRvEQQKUA+JZNAm3EWlgaOBGpyFDqQnDHMef0= +github.com/go-openapi/swag v0.24.1 h1:DPdYTZKo6AQCRqzwr/kGkxJzHhpKxZ9i/oX0zag+MF8= +github.com/go-openapi/swag v0.24.1/go.mod h1:sm8I3lCPlspsBBwUm1t5oZeWZS0s7m/A+Psg0ooRU0A= +github.com/go-openapi/swag/cmdutils v0.24.0 h1:KlRCffHwXFI6E5MV9n8o8zBRElpY4uK4yWyAMWETo9I= +github.com/go-openapi/swag/cmdutils v0.24.0/go.mod h1:uxib2FAeQMByyHomTlsP8h1TtPd54Msu2ZDU/H5Vuf8= +github.com/go-openapi/swag/conv v0.24.0 h1:ejB9+7yogkWly6pnruRX45D1/6J+ZxRu92YFivx54ik= +github.com/go-openapi/swag/conv v0.24.0/go.mod h1:jbn140mZd7EW2g8a8Y5bwm8/Wy1slLySQQ0ND6DPc2c= +github.com/go-openapi/swag/fileutils v0.24.0 h1:U9pCpqp4RUytnD689Ek/N1d2N/a//XCeqoH508H5oak= +github.com/go-openapi/swag/fileutils v0.24.0/go.mod h1:3SCrCSBHyP1/N+3oErQ1gP+OX1GV2QYFSnrTbzwli90= +github.com/go-openapi/swag/jsonname v0.24.0 h1:2wKS9bgRV/xB8c62Qg16w4AUiIrqqiniJFtZGi3dg5k= +github.com/go-openapi/swag/jsonname v0.24.0/go.mod h1:GXqrPzGJe611P7LG4QB9JKPtUZ7flE4DOVechNaDd7Q= +github.com/go-openapi/swag/jsonutils v0.24.0 h1:F1vE1q4pg1xtO3HTyJYRmEuJ4jmIp2iZ30bzW5XgZts= +github.com/go-openapi/swag/jsonutils v0.24.0/go.mod h1:vBowZtF5Z4DDApIoxcIVfR8v0l9oq5PpYRUuteVu6f0= +github.com/go-openapi/swag/loading v0.24.0 h1:ln/fWTwJp2Zkj5DdaX4JPiddFC5CHQpvaBKycOlceYc= +github.com/go-openapi/swag/loading v0.24.0/go.mod h1:gShCN4woKZYIxPxbfbyHgjXAhO61m88tmjy0lp/LkJk= +github.com/go-openapi/swag/mangling v0.24.0 h1:PGOQpViCOUroIeak/Uj/sjGAq9LADS3mOyjznmHy2pk= +github.com/go-openapi/swag/mangling v0.24.0/go.mod h1:Jm5Go9LHkycsz0wfoaBDkdc4CkpuSnIEf62brzyCbhc= +github.com/go-openapi/swag/netutils v0.24.0 h1:Bz02HRjYv8046Ycg/w80q3g9QCWeIqTvlyOjQPDjD8w= +github.com/go-openapi/swag/netutils v0.24.0/go.mod h1:WRgiHcYTnx+IqfMCtu0hy9oOaPR0HnPbmArSRN1SkZM= +github.com/go-openapi/swag/stringutils v0.24.0 h1:i4Z/Jawf9EvXOLUbT97O0HbPUja18VdBxeadyAqS1FM= +github.com/go-openapi/swag/stringutils v0.24.0/go.mod h1:5nUXB4xA0kw2df5PRipZDslPJgJut+NjL7D25zPZ/4w= +github.com/go-openapi/swag/typeutils v0.24.0 h1:d3szEGzGDf4L2y1gYOSSLeK6h46F+zibnEas2Jm/wIw= +github.com/go-openapi/swag/typeutils v0.24.0/go.mod h1:q8C3Kmk/vh2VhpCLaoR2MVWOGP8y7Jc8l82qCTd1DYI= +github.com/go-openapi/swag/yamlutils v0.24.0 h1:bhw4894A7Iw6ne+639hsBNRHg9iZg/ISrOVr+sJGp4c= +github.com/go-openapi/swag/yamlutils v0.24.0/go.mod h1:DpKv5aYuaGm/sULePoeiG8uwMpZSfReo1HR3Ik0yaG8= github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= diff --git a/internal/antest/helpers.go b/internal/antest/helpers.go index bcefe63..c49e4b2 100644 --- a/internal/antest/helpers.go +++ b/internal/antest/helpers.go @@ -9,7 +9,7 @@ import ( "testing" "github.com/go-openapi/spec" - "github.com/go-openapi/swag" + "github.com/go-openapi/swag/loading" "github.com/stretchr/testify/require" ) @@ -33,10 +33,10 @@ func initPathLoader() { spec.PathLoader = func(path string) (json.RawMessage, error) { ext := filepath.Ext(path) if ext == ".yml" || ext == ".yaml" { - return swag.YAMLDoc(path) + return loading.YAMLDoc(path) } - data, err := swag.LoadFromFileOrHTTP(path) + data, err := loading.LoadFromFileOrHTTP(path) if err != nil { return nil, err } diff --git a/internal/flatten/operations/operations.go b/internal/flatten/operations/operations.go index 7f3a2b8..a1911b0 100644 --- a/internal/flatten/operations/operations.go +++ b/internal/flatten/operations/operations.go @@ -2,12 +2,13 @@ package operations import ( "path" + "slices" "sort" "strings" "github.com/go-openapi/jsonpointer" "github.com/go-openapi/spec" - "github.com/go-openapi/swag" + "github.com/go-openapi/swag/mangling" ) // AllOpRefsByRef returns an index of sortable operations @@ -50,12 +51,13 @@ type Provider interface { // GatherOperations builds a map of sorted operations from a spec func GatherOperations(specDoc Provider, operationIDs []string) map[string]OpRef { var oprefs OpRefs + mangler := mangling.NewNameMangler() for method, pathItem := range specDoc.Operations() { for pth, operation := range pathItem { vv := *operation oprefs = append(oprefs, OpRef{ - Key: swag.ToGoName(strings.ToLower(method) + " " + pth), + Key: mangler.ToGoName(strings.ToLower(method) + " " + pth), Method: method, Path: pth, ID: vv.ID, @@ -79,7 +81,7 @@ func GatherOperations(specDoc Provider, operationIDs []string) map[string]OpRef nm = opr.Key } - if len(operationIDs) == 0 || swag.ContainsStrings(operationIDs, opr.ID) || swag.ContainsStrings(operationIDs, nm) { + if len(operationIDs) == 0 || slices.Contains(operationIDs, opr.ID) || slices.Contains(operationIDs, nm) { opr.ID = nm opr.Op.ID = nm operations[nm] = opr diff --git a/internal/flatten/schutils/flatten_schema.go b/internal/flatten/schutils/flatten_schema.go index 23ed56e..fa7f6bf 100644 --- a/internal/flatten/schutils/flatten_schema.go +++ b/internal/flatten/schutils/flatten_schema.go @@ -4,7 +4,7 @@ package schutils import ( "github.com/go-openapi/spec" - "github.com/go-openapi/swag" + "github.com/go-openapi/swag/jsonutils" ) const allocLargeMap = 150 @@ -25,7 +25,7 @@ func Save(sp *spec.Swagger, name string, schema *spec.Schema) { // Clone deep-clones a schema func Clone(schema *spec.Schema) *spec.Schema { var sch spec.Schema - _ = swag.FromDynamicJSON(schema, &sch) + _ = jsonutils.FromDynamicJSON(schema, &sch) return &sch }