Skip to content

Commit b1ecac1

Browse files
committed
chore: adopted swag v0.24.0 modules
go-openapi/swag has introduced a new API to better insulate dependencies. We move to the new modules, even though at this stage this doesn't change our indirect dependencies. Signed-off-by: Frederic BIDON <fredbi@yahoo.com>
1 parent a8da6a2 commit b1ecac1

File tree

8 files changed

+54
-17
lines changed

8 files changed

+54
-17
lines changed

analysis_test/spec_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/go-openapi/analysis/internal/antest"
1212
"github.com/go-openapi/loads"
1313
"github.com/go-openapi/spec"
14-
"github.com/go-openapi/swag"
14+
"github.com/go-openapi/swag/loading"
1515
"github.com/stretchr/testify/assert"
1616
"github.com/stretchr/testify/require"
1717
)
@@ -29,7 +29,7 @@ func Test_FlattenAzure(t *testing.T) {
2929

3030
// 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
3131
url := "../fixtures/azure/publicIpAddress.json"
32-
byts, err := swag.LoadFromFileOrHTTP(url)
32+
byts, err := loading.LoadFromFileOrHTTP(url)
3333
assert.NoError(t, err)
3434
swagger := &spec.Swagger{}
3535
require.NoError(t, swagger.UnmarshalJSON(byts))

analyzer.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
"github.com/go-openapi/jsonpointer"
2424
"github.com/go-openapi/spec"
25-
"github.com/go-openapi/swag"
25+
"github.com/go-openapi/swag/mangling"
2626
)
2727

2828
const (
@@ -307,8 +307,9 @@ func fieldNameFromParam(param *spec.Parameter) string {
307307
if nm, ok := param.Extensions.GetString("go-name"); ok {
308308
return nm
309309
}
310+
mangler := mangling.NewNameMangler()
310311

311-
return swag.ToGoName(param.Name)
312+
return mangler.ToGoName(param.Name)
312313
}
313314

314315
// ErrorOnParamFunc is a callback function to be invoked

flatten_name.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/go-openapi/analysis/internal/flatten/schutils"
1212
"github.com/go-openapi/analysis/internal/flatten/sortref"
1313
"github.com/go-openapi/spec"
14-
"github.com/go-openapi/swag"
14+
"github.com/go-openapi/swag/mangling"
1515
)
1616

1717
// InlineSchemaNamer finds a new name for an inlined type
@@ -270,8 +270,9 @@ func mangler(o *FlattenOpts) func(string) string {
270270
if o.KeepNames {
271271
return func(in string) string { return in }
272272
}
273+
mangler := mangling.NewNameMangler()
273274

274-
return swag.ToJSONName
275+
return mangler.ToJSONName
275276
}
276277

277278
func nameFromRef(ref spec.Ref, o *FlattenOpts) string {

go.mod

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ require (
44
github.com/go-openapi/jsonpointer v0.21.2
55
github.com/go-openapi/spec v0.21.0
66
github.com/go-openapi/strfmt v0.23.0
7-
github.com/go-openapi/swag v0.23.1
7+
github.com/go-openapi/swag/jsonutils v0.24.0
8+
github.com/go-openapi/swag/loading v0.24.0
9+
github.com/go-openapi/swag/mangling v0.24.0
810
github.com/stretchr/testify v1.11.1
911
)
1012

@@ -13,6 +15,15 @@ require (
1315
github.com/davecgh/go-spew v1.1.1 // indirect
1416
github.com/go-openapi/errors v0.22.0 // indirect
1517
github.com/go-openapi/jsonreference v0.21.0 // indirect
18+
github.com/go-openapi/swag v0.24.1 // indirect
19+
github.com/go-openapi/swag/cmdutils v0.24.0 // indirect
20+
github.com/go-openapi/swag/conv v0.24.0 // indirect
21+
github.com/go-openapi/swag/fileutils v0.24.0 // indirect
22+
github.com/go-openapi/swag/jsonname v0.24.0 // indirect
23+
github.com/go-openapi/swag/netutils v0.24.0 // indirect
24+
github.com/go-openapi/swag/stringutils v0.24.0 // indirect
25+
github.com/go-openapi/swag/typeutils v0.24.0 // indirect
26+
github.com/go-openapi/swag/yamlutils v0.24.0 // indirect
1627
github.com/google/uuid v1.6.0 // indirect
1728
github.com/josharian/intern v1.0.0 // indirect
1829
github.com/mailru/easyjson v0.9.0 // indirect

go.sum

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,30 @@ github.com/go-openapi/spec v0.21.0 h1:LTVzPc3p/RzRnkQqLRndbAzjY0d0BCL72A6j3CdL9Z
1212
github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk=
1313
github.com/go-openapi/strfmt v0.23.0 h1:nlUS6BCqcnAk0pyhi9Y+kdDVZdZMHfEKQiS4HaMgO/c=
1414
github.com/go-openapi/strfmt v0.23.0/go.mod h1:NrtIpfKtWIygRkKVsxh7XQMDQW5HKQl6S5ik2elW+K4=
15-
github.com/go-openapi/swag v0.23.1 h1:lpsStH0n2ittzTnbaSloVZLuB5+fvSY/+hnagBjSNZU=
16-
github.com/go-openapi/swag v0.23.1/go.mod h1:STZs8TbRvEQQKUA+JZNAm3EWlgaOBGpyFDqQnDHMef0=
15+
github.com/go-openapi/swag v0.24.1 h1:DPdYTZKo6AQCRqzwr/kGkxJzHhpKxZ9i/oX0zag+MF8=
16+
github.com/go-openapi/swag v0.24.1/go.mod h1:sm8I3lCPlspsBBwUm1t5oZeWZS0s7m/A+Psg0ooRU0A=
17+
github.com/go-openapi/swag/cmdutils v0.24.0 h1:KlRCffHwXFI6E5MV9n8o8zBRElpY4uK4yWyAMWETo9I=
18+
github.com/go-openapi/swag/cmdutils v0.24.0/go.mod h1:uxib2FAeQMByyHomTlsP8h1TtPd54Msu2ZDU/H5Vuf8=
19+
github.com/go-openapi/swag/conv v0.24.0 h1:ejB9+7yogkWly6pnruRX45D1/6J+ZxRu92YFivx54ik=
20+
github.com/go-openapi/swag/conv v0.24.0/go.mod h1:jbn140mZd7EW2g8a8Y5bwm8/Wy1slLySQQ0ND6DPc2c=
21+
github.com/go-openapi/swag/fileutils v0.24.0 h1:U9pCpqp4RUytnD689Ek/N1d2N/a//XCeqoH508H5oak=
22+
github.com/go-openapi/swag/fileutils v0.24.0/go.mod h1:3SCrCSBHyP1/N+3oErQ1gP+OX1GV2QYFSnrTbzwli90=
23+
github.com/go-openapi/swag/jsonname v0.24.0 h1:2wKS9bgRV/xB8c62Qg16w4AUiIrqqiniJFtZGi3dg5k=
24+
github.com/go-openapi/swag/jsonname v0.24.0/go.mod h1:GXqrPzGJe611P7LG4QB9JKPtUZ7flE4DOVechNaDd7Q=
25+
github.com/go-openapi/swag/jsonutils v0.24.0 h1:F1vE1q4pg1xtO3HTyJYRmEuJ4jmIp2iZ30bzW5XgZts=
26+
github.com/go-openapi/swag/jsonutils v0.24.0/go.mod h1:vBowZtF5Z4DDApIoxcIVfR8v0l9oq5PpYRUuteVu6f0=
27+
github.com/go-openapi/swag/loading v0.24.0 h1:ln/fWTwJp2Zkj5DdaX4JPiddFC5CHQpvaBKycOlceYc=
28+
github.com/go-openapi/swag/loading v0.24.0/go.mod h1:gShCN4woKZYIxPxbfbyHgjXAhO61m88tmjy0lp/LkJk=
29+
github.com/go-openapi/swag/mangling v0.24.0 h1:PGOQpViCOUroIeak/Uj/sjGAq9LADS3mOyjznmHy2pk=
30+
github.com/go-openapi/swag/mangling v0.24.0/go.mod h1:Jm5Go9LHkycsz0wfoaBDkdc4CkpuSnIEf62brzyCbhc=
31+
github.com/go-openapi/swag/netutils v0.24.0 h1:Bz02HRjYv8046Ycg/w80q3g9QCWeIqTvlyOjQPDjD8w=
32+
github.com/go-openapi/swag/netutils v0.24.0/go.mod h1:WRgiHcYTnx+IqfMCtu0hy9oOaPR0HnPbmArSRN1SkZM=
33+
github.com/go-openapi/swag/stringutils v0.24.0 h1:i4Z/Jawf9EvXOLUbT97O0HbPUja18VdBxeadyAqS1FM=
34+
github.com/go-openapi/swag/stringutils v0.24.0/go.mod h1:5nUXB4xA0kw2df5PRipZDslPJgJut+NjL7D25zPZ/4w=
35+
github.com/go-openapi/swag/typeutils v0.24.0 h1:d3szEGzGDf4L2y1gYOSSLeK6h46F+zibnEas2Jm/wIw=
36+
github.com/go-openapi/swag/typeutils v0.24.0/go.mod h1:q8C3Kmk/vh2VhpCLaoR2MVWOGP8y7Jc8l82qCTd1DYI=
37+
github.com/go-openapi/swag/yamlutils v0.24.0 h1:bhw4894A7Iw6ne+639hsBNRHg9iZg/ISrOVr+sJGp4c=
38+
github.com/go-openapi/swag/yamlutils v0.24.0/go.mod h1:DpKv5aYuaGm/sULePoeiG8uwMpZSfReo1HR3Ik0yaG8=
1739
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
1840
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
1941
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=

internal/antest/helpers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"testing"
1010

1111
"github.com/go-openapi/spec"
12-
"github.com/go-openapi/swag"
12+
"github.com/go-openapi/swag/loading"
1313
"github.com/stretchr/testify/require"
1414
)
1515

@@ -33,10 +33,10 @@ func initPathLoader() {
3333
spec.PathLoader = func(path string) (json.RawMessage, error) {
3434
ext := filepath.Ext(path)
3535
if ext == ".yml" || ext == ".yaml" {
36-
return swag.YAMLDoc(path)
36+
return loading.YAMLDoc(path)
3737
}
3838

39-
data, err := swag.LoadFromFileOrHTTP(path)
39+
data, err := loading.LoadFromFileOrHTTP(path)
4040
if err != nil {
4141
return nil, err
4242
}

internal/flatten/operations/operations.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package operations
22

33
import (
44
"path"
5+
"slices"
56
"sort"
67
"strings"
78

89
"github.com/go-openapi/jsonpointer"
910
"github.com/go-openapi/spec"
10-
"github.com/go-openapi/swag"
11+
"github.com/go-openapi/swag/mangling"
1112
)
1213

1314
// AllOpRefsByRef returns an index of sortable operations
@@ -50,12 +51,13 @@ type Provider interface {
5051
// GatherOperations builds a map of sorted operations from a spec
5152
func GatherOperations(specDoc Provider, operationIDs []string) map[string]OpRef {
5253
var oprefs OpRefs
54+
mangler := mangling.NewNameMangler()
5355

5456
for method, pathItem := range specDoc.Operations() {
5557
for pth, operation := range pathItem {
5658
vv := *operation
5759
oprefs = append(oprefs, OpRef{
58-
Key: swag.ToGoName(strings.ToLower(method) + " " + pth),
60+
Key: mangler.ToGoName(strings.ToLower(method) + " " + pth),
5961
Method: method,
6062
Path: pth,
6163
ID: vv.ID,
@@ -79,7 +81,7 @@ func GatherOperations(specDoc Provider, operationIDs []string) map[string]OpRef
7981
nm = opr.Key
8082
}
8183

82-
if len(operationIDs) == 0 || swag.ContainsStrings(operationIDs, opr.ID) || swag.ContainsStrings(operationIDs, nm) {
84+
if len(operationIDs) == 0 || slices.Contains(operationIDs, opr.ID) || slices.Contains(operationIDs, nm) {
8385
opr.ID = nm
8486
opr.Op.ID = nm
8587
operations[nm] = opr

internal/flatten/schutils/flatten_schema.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package schutils
44

55
import (
66
"github.com/go-openapi/spec"
7-
"github.com/go-openapi/swag"
7+
"github.com/go-openapi/swag/jsonutils"
88
)
99

1010
const allocLargeMap = 150
@@ -25,7 +25,7 @@ func Save(sp *spec.Swagger, name string, schema *spec.Schema) {
2525
// Clone deep-clones a schema
2626
func Clone(schema *spec.Schema) *spec.Schema {
2727
var sch spec.Schema
28-
_ = swag.FromDynamicJSON(schema, &sch)
28+
_ = jsonutils.FromDynamicJSON(schema, &sch)
2929

3030
return &sch
3131
}

0 commit comments

Comments
 (0)