Skip to content

Commit 5806528

Browse files
committed
chore: adopted swag v0.24.0 modules
go-openapi 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 <[email protected]>
1 parent d7c0e6d commit 5806528

File tree

9 files changed

+88
-39
lines changed

9 files changed

+88
-39
lines changed

go.mod

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,36 @@ require (
44
github.com/davecgh/go-spew v1.1.1
55
github.com/go-openapi/analysis v0.23.0
66
github.com/go-openapi/errors v0.22.2
7-
github.com/go-openapi/jsonpointer v0.21.2
7+
github.com/go-openapi/jsonpointer v0.22.0
88
github.com/go-openapi/loads v0.22.0
99
github.com/go-openapi/spec v0.21.0
1010
github.com/go-openapi/strfmt v0.23.0
11-
github.com/go-openapi/swag v0.23.1
11+
github.com/go-openapi/swag/conv v0.24.0
12+
github.com/go-openapi/swag/fileutils v0.24.0
13+
github.com/go-openapi/swag/jsonutils v0.24.0
14+
github.com/go-openapi/swag/stringutils v0.24.0
1215
github.com/stretchr/testify v1.11.1
1316
gopkg.in/yaml.v3 v3.0.1
1417
)
1518

1619
require (
1720
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
18-
github.com/go-openapi/jsonreference v0.21.0 // indirect
21+
github.com/go-openapi/jsonreference v0.21.1 // indirect
22+
github.com/go-openapi/swag v0.24.1 // indirect
23+
github.com/go-openapi/swag/cmdutils v0.24.0 // indirect
24+
github.com/go-openapi/swag/jsonname v0.24.0 // indirect
25+
github.com/go-openapi/swag/loading v0.24.0 // indirect
26+
github.com/go-openapi/swag/mangling v0.24.0 // indirect
27+
github.com/go-openapi/swag/netutils v0.24.0 // indirect
28+
github.com/go-openapi/swag/typeutils v0.24.0 // indirect
29+
github.com/go-openapi/swag/yamlutils v0.24.0 // indirect
1930
github.com/google/uuid v1.6.0 // indirect
2031
github.com/josharian/intern v1.0.0 // indirect
2132
github.com/mailru/easyjson v0.9.0 // indirect
2233
github.com/mitchellh/mapstructure v1.5.0 // indirect
2334
github.com/oklog/ulid v1.3.1 // indirect
2435
github.com/pmezard/go-difflib v1.0.0 // indirect
25-
go.mongodb.org/mongo-driver v1.14.0 // indirect
36+
go.mongodb.org/mongo-driver v1.17.4 // indirect
2637
)
2738

2839
go 1.20

go.sum

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,41 @@ github.com/go-openapi/analysis v0.23.0 h1:aGday7OWupfMs+LbmLZG4k0MYXIANxcuBTYUC0
66
github.com/go-openapi/analysis v0.23.0/go.mod h1:9mz9ZWaSlV8TvjQHLl2mUW2PbZtemkE8yA5v22ohupo=
77
github.com/go-openapi/errors v0.22.2 h1:rdxhzcBUazEcGccKqbY1Y7NS8FDcMyIRr0934jrYnZg=
88
github.com/go-openapi/errors v0.22.2/go.mod h1:+n/5UdIqdVnLIJ6Q9Se8HNGUXYaY6CN8ImWzfi/Gzp0=
9-
github.com/go-openapi/jsonpointer v0.21.2 h1:AqQaNADVwq/VnkCmQg6ogE+M3FOsKTytwges0JdwVuA=
10-
github.com/go-openapi/jsonpointer v0.21.2/go.mod h1:50I1STOfbY1ycR8jGz8DaMeLCdXiI6aDteEdRNNzpdk=
11-
github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF2+tg1TRrwQ=
12-
github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4=
9+
github.com/go-openapi/jsonpointer v0.22.0 h1:TmMhghgNef9YXxTu1tOopo+0BGEytxA+okbry0HjZsM=
10+
github.com/go-openapi/jsonpointer v0.22.0/go.mod h1:xt3jV88UtExdIkkL7NloURjRQjbeUgcxFblMjq2iaiU=
11+
github.com/go-openapi/jsonreference v0.21.1 h1:bSKrcl8819zKiOgxkbVNRUBIr6Wwj9KYrDbMjRs0cDA=
12+
github.com/go-openapi/jsonreference v0.21.1/go.mod h1:PWs8rO4xxTUqKGu+lEvvCxD5k2X7QYkKAepJyCmSTT8=
1313
github.com/go-openapi/loads v0.22.0 h1:ECPGd4jX1U6NApCGG1We+uEozOAvXvJSF4nnwHZ8Aco=
1414
github.com/go-openapi/loads v0.22.0/go.mod h1:yLsaTCS92mnSAZX5WWoxszLj0u+Ojl+Zs5Stn1oF+rs=
1515
github.com/go-openapi/spec v0.21.0 h1:LTVzPc3p/RzRnkQqLRndbAzjY0d0BCL72A6j3CdL9ZY=
1616
github.com/go-openapi/spec v0.21.0/go.mod h1:78u6VdPw81XU44qEWGhtr982gJ5BWg2c0I5XwVMotYk=
1717
github.com/go-openapi/strfmt v0.23.0 h1:nlUS6BCqcnAk0pyhi9Y+kdDVZdZMHfEKQiS4HaMgO/c=
1818
github.com/go-openapi/strfmt v0.23.0/go.mod h1:NrtIpfKtWIygRkKVsxh7XQMDQW5HKQl6S5ik2elW+K4=
19-
github.com/go-openapi/swag v0.23.1 h1:lpsStH0n2ittzTnbaSloVZLuB5+fvSY/+hnagBjSNZU=
20-
github.com/go-openapi/swag v0.23.1/go.mod h1:STZs8TbRvEQQKUA+JZNAm3EWlgaOBGpyFDqQnDHMef0=
21-
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
19+
github.com/go-openapi/swag v0.24.1 h1:DPdYTZKo6AQCRqzwr/kGkxJzHhpKxZ9i/oX0zag+MF8=
20+
github.com/go-openapi/swag v0.24.1/go.mod h1:sm8I3lCPlspsBBwUm1t5oZeWZS0s7m/A+Psg0ooRU0A=
21+
github.com/go-openapi/swag/cmdutils v0.24.0 h1:KlRCffHwXFI6E5MV9n8o8zBRElpY4uK4yWyAMWETo9I=
22+
github.com/go-openapi/swag/cmdutils v0.24.0/go.mod h1:uxib2FAeQMByyHomTlsP8h1TtPd54Msu2ZDU/H5Vuf8=
23+
github.com/go-openapi/swag/conv v0.24.0 h1:ejB9+7yogkWly6pnruRX45D1/6J+ZxRu92YFivx54ik=
24+
github.com/go-openapi/swag/conv v0.24.0/go.mod h1:jbn140mZd7EW2g8a8Y5bwm8/Wy1slLySQQ0ND6DPc2c=
25+
github.com/go-openapi/swag/fileutils v0.24.0 h1:U9pCpqp4RUytnD689Ek/N1d2N/a//XCeqoH508H5oak=
26+
github.com/go-openapi/swag/fileutils v0.24.0/go.mod h1:3SCrCSBHyP1/N+3oErQ1gP+OX1GV2QYFSnrTbzwli90=
27+
github.com/go-openapi/swag/jsonname v0.24.0 h1:2wKS9bgRV/xB8c62Qg16w4AUiIrqqiniJFtZGi3dg5k=
28+
github.com/go-openapi/swag/jsonname v0.24.0/go.mod h1:GXqrPzGJe611P7LG4QB9JKPtUZ7flE4DOVechNaDd7Q=
29+
github.com/go-openapi/swag/jsonutils v0.24.0 h1:F1vE1q4pg1xtO3HTyJYRmEuJ4jmIp2iZ30bzW5XgZts=
30+
github.com/go-openapi/swag/jsonutils v0.24.0/go.mod h1:vBowZtF5Z4DDApIoxcIVfR8v0l9oq5PpYRUuteVu6f0=
31+
github.com/go-openapi/swag/loading v0.24.0 h1:ln/fWTwJp2Zkj5DdaX4JPiddFC5CHQpvaBKycOlceYc=
32+
github.com/go-openapi/swag/loading v0.24.0/go.mod h1:gShCN4woKZYIxPxbfbyHgjXAhO61m88tmjy0lp/LkJk=
33+
github.com/go-openapi/swag/mangling v0.24.0 h1:PGOQpViCOUroIeak/Uj/sjGAq9LADS3mOyjznmHy2pk=
34+
github.com/go-openapi/swag/mangling v0.24.0/go.mod h1:Jm5Go9LHkycsz0wfoaBDkdc4CkpuSnIEf62brzyCbhc=
35+
github.com/go-openapi/swag/netutils v0.24.0 h1:Bz02HRjYv8046Ycg/w80q3g9QCWeIqTvlyOjQPDjD8w=
36+
github.com/go-openapi/swag/netutils v0.24.0/go.mod h1:WRgiHcYTnx+IqfMCtu0hy9oOaPR0HnPbmArSRN1SkZM=
37+
github.com/go-openapi/swag/stringutils v0.24.0 h1:i4Z/Jawf9EvXOLUbT97O0HbPUja18VdBxeadyAqS1FM=
38+
github.com/go-openapi/swag/stringutils v0.24.0/go.mod h1:5nUXB4xA0kw2df5PRipZDslPJgJut+NjL7D25zPZ/4w=
39+
github.com/go-openapi/swag/typeutils v0.24.0 h1:d3szEGzGDf4L2y1gYOSSLeK6h46F+zibnEas2Jm/wIw=
40+
github.com/go-openapi/swag/typeutils v0.24.0/go.mod h1:q8C3Kmk/vh2VhpCLaoR2MVWOGP8y7Jc8l82qCTd1DYI=
41+
github.com/go-openapi/swag/yamlutils v0.24.0 h1:bhw4894A7Iw6ne+639hsBNRHg9iZg/ISrOVr+sJGp4c=
42+
github.com/go-openapi/swag/yamlutils v0.24.0/go.mod h1:DpKv5aYuaGm/sULePoeiG8uwMpZSfReo1HR3Ik0yaG8=
43+
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
2244
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
2345
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
2446
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
@@ -36,8 +58,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
3658
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
3759
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
3860
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
39-
go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80=
40-
go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c=
61+
go.mongodb.org/mongo-driver v1.17.4 h1:jUorfmVzljjr0FLzYQsGP8cgN/qzzxlY9Vh0C9KFXVw=
62+
go.mongodb.org/mongo-driver v1.17.4/go.mod h1:Hy04i7O2kC4RS06ZrhPRqj/u4DTYkFDAAccj+rVKqgQ=
4163
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
4264
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
4365
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=

jsonschema_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
"github.com/go-openapi/spec"
2727
"github.com/go-openapi/strfmt"
28-
"github.com/go-openapi/swag"
28+
"github.com/go-openapi/swag/stringutils"
2929
"github.com/stretchr/testify/assert"
3030
"github.com/stretchr/testify/require"
3131
)
@@ -93,15 +93,15 @@ var extendedFixtures = []string{
9393
}
9494

9595
func isEnabled(nm string) bool {
96-
return swag.ContainsStringsCI(enabled(), nm)
96+
return stringutils.ContainsStringsCI(enabled(), nm)
9797
}
9898

9999
func isOptionalEnabled(nm string) bool {
100-
return swag.ContainsStringsCI(optionalFixtures, nm)
100+
return stringutils.ContainsStringsCI(optionalFixtures, nm)
101101
}
102102

103103
func isExtendedEnabled(nm string) bool {
104-
return swag.ContainsStringsCI(extendedFixtures, nm)
104+
return stringutils.ContainsStringsCI(extendedFixtures, nm)
105105
}
106106

107107
func TestJSONSchemaSuite(t *testing.T) {

schema.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"github.com/go-openapi/errors"
2222
"github.com/go-openapi/spec"
2323
"github.com/go-openapi/strfmt"
24-
"github.com/go-openapi/swag"
24+
"github.com/go-openapi/swag/jsonutils"
2525
)
2626

2727
// SchemaValidator validates data against a JSON schema
@@ -176,7 +176,15 @@ func (s *SchemaValidator) Validate(data interface{}) *Result {
176176
// this means that all strfmt types passed here (e.g. strfmt.Datetime, etc..)
177177
// are converted here to strings, and structs are systematically converted
178178
// to map[string]interface{}.
179-
d = swag.ToDynamicJSON(data)
179+
var dd any
180+
if err := jsonutils.FromDynamicJSON(data, &dd); err != nil {
181+
result.AddErrors(err)
182+
result.Inc()
183+
184+
return result
185+
}
186+
187+
d = dd
180188
}
181189

182190
// TODO: this part should be handed over to type validator

schema_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525

2626
"github.com/go-openapi/spec"
2727
"github.com/go-openapi/strfmt"
28-
"github.com/go-openapi/swag"
28+
"github.com/go-openapi/swag/conv"
2929
)
3030

3131
func TestSchemaValidator_Validate_Pattern(t *testing.T) {
@@ -171,7 +171,7 @@ func TestSchemaValidator_EdgeCases(t *testing.T) {
171171
r = s.Validate(j)
172172
assert.True(t, r.IsValid())
173173

174-
bignum := swag.FormatFloat64(math.MaxFloat64)
174+
bignum := conv.FormatFloat(math.MaxFloat64)
175175
j = json.Number(bignum)
176176
r = s.Validate(j)
177177
assert.False(t, r.IsValid())

spec.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"github.com/go-openapi/loads"
2929
"github.com/go-openapi/spec"
3030
"github.com/go-openapi/strfmt"
31-
"github.com/go-openapi/swag"
31+
"github.com/go-openapi/swag/jsonutils"
3232
)
3333

3434
// Spec validates an OpenAPI 2.0 specification document.
@@ -696,7 +696,13 @@ func (s *SpecValidator) validateParameters() *Result {
696696
for _, pr := range paramHelp.safeExpandedParamsFor(path, method, op.ID, res, s) {
697697
// An expanded parameter must validate the Parameter schema (an unexpanded $ref always passes high-level schema validation)
698698
schv := newSchemaValidator(&paramSchema, s.schema, fmt.Sprintf("%s.%s.parameters.%s", path, method, pr.Name), s.KnownFormats, s.schemaOptions)
699-
obj := swag.ToDynamicJSON(pr)
699+
var obj any
700+
if err := jsonutils.FromDynamicJSON(pr, &obj); err != nil {
701+
res.AddErrors(err)
702+
703+
return res
704+
}
705+
700706
res.Merge(schv.Validate(obj))
701707

702708
// Validate pattern regexp for parameters with a Pattern property

type.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import (
2121
"github.com/go-openapi/errors"
2222
"github.com/go-openapi/spec"
2323
"github.com/go-openapi/strfmt"
24-
"github.com/go-openapi/swag"
24+
"github.com/go-openapi/swag/conv"
25+
"github.com/go-openapi/swag/fileutils"
2526
)
2627

2728
type typeValidator struct {
@@ -100,7 +101,7 @@ func (t *typeValidator) Validate(data interface{}) *Result {
100101
// TODO: check json.Number (see schema.go)
101102
isLowerInt := t.Format == integerFormatInt64 && format == integerFormatInt32
102103
isLowerFloat := t.Format == numberFormatFloat64 && format == numberFormatFloat32
103-
isFloatInt := schType == numberType && swag.IsFloat64AJSONInteger(val.Float()) && t.Type.Contains(integerType)
104+
isFloatInt := schType == numberType && conv.IsFloat64AJSONInteger(val.Float()) && t.Type.Contains(integerType)
104105
isIntFloat := schType == integerType && t.Type.Contains(numberType)
105106

106107
if kind != reflect.String && kind != reflect.Slice && t.Format != "" && !t.Type.Contains(schType) && format != t.Format && !isFloatInt && !isIntFloat && !isLowerInt && !isLowerFloat {
@@ -134,7 +135,7 @@ func (t *typeValidator) schemaInfoForType(data interface{}) (string, string) {
134135
return stringType, stringFormatDateTime
135136
case strfmt.Duration, *strfmt.Duration:
136137
return stringType, stringFormatDuration
137-
case swag.File, *swag.File:
138+
case fileutils.File, *fileutils.File:
138139
return fileType, ""
139140
case strfmt.Email, *strfmt.Email:
140141
return stringType, stringFormatEmail

type_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ import (
2121
"time"
2222

2323
"github.com/go-openapi/strfmt"
24-
"github.com/go-openapi/swag"
24+
"github.com/go-openapi/swag/fileutils"
25+
2526
"github.com/stretchr/testify/assert"
2627
"github.com/stretchr/testify/require"
2728
)
@@ -52,7 +53,7 @@ func TestType_schemaInfoForType(t *testing.T) {
5253
},
5354
{
5455
// TODO: this exception is really prone to errors: should alias runtime.File in strfmt
55-
value: swag.File{},
56+
value: fileutils.File{},
5657
expectedJSONType: "file",
5758
expectedSwaggerFormat: "",
5859
},
@@ -287,7 +288,7 @@ func TestType_schemaInfoForType(t *testing.T) {
287288
}
288289

289290
// Check file declarations as io.ReadCloser are properly detected
290-
myFile := swag.File{}
291+
myFile := fileutils.File{}
291292
var myReader io.ReadCloser = &myFile
292293
jsonType, swaggerFormat := v.schemaInfoForType(myReader)
293294
assert.Equal(t, "file", jsonType)

values.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323

2424
"github.com/go-openapi/errors"
2525
"github.com/go-openapi/strfmt"
26-
"github.com/go-openapi/swag"
26+
"github.com/go-openapi/swag/conv"
2727
)
2828

2929
type valueError string
@@ -266,7 +266,7 @@ func MultipleOf(path, in string, data, factor float64) *errors.Validation {
266266
} else {
267267
mult = data / factor
268268
}
269-
if !swag.IsFloat64AJSONInteger(mult) {
269+
if !conv.IsFloat64AJSONInteger(mult) {
270270
return errors.NotMultipleOf(path, in, factor, data)
271271
}
272272
return nil
@@ -410,11 +410,11 @@ func IsValueValidAgainstRange(val interface{}, typeName, format, prefix, path st
410410
var stringRep string
411411
switch kind { //nolint:exhaustive
412412
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
413-
stringRep = swag.FormatUint64(valueHelp.asUint64(val))
413+
stringRep = conv.FormatUinteger(valueHelp.asUint64(val))
414414
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
415-
stringRep = swag.FormatInt64(valueHelp.asInt64(val))
415+
stringRep = conv.FormatInteger(valueHelp.asInt64(val))
416416
case reflect.Float32, reflect.Float64:
417-
stringRep = swag.FormatFloat64(valueHelp.asFloat64(val))
417+
stringRep = conv.FormatFloat(valueHelp.asFloat64(val))
418418
default:
419419
return fmt.Errorf("%s value number range checking called with invalid (non numeric) val type in %s: %w", prefix, path, ErrValue)
420420
}
@@ -425,22 +425,22 @@ func IsValueValidAgainstRange(val interface{}, typeName, format, prefix, path st
425425
case integerType:
426426
switch format {
427427
case integerFormatInt32:
428-
_, errVal = swag.ConvertInt32(stringRep)
428+
_, errVal = conv.ConvertInt32(stringRep)
429429
case integerFormatUInt32:
430-
_, errVal = swag.ConvertUint32(stringRep)
430+
_, errVal = conv.ConvertUint32(stringRep)
431431
case integerFormatUInt64:
432-
_, errVal = swag.ConvertUint64(stringRep)
432+
_, errVal = conv.ConvertUint64(stringRep)
433433
case integerFormatInt64:
434434
fallthrough
435435
default:
436-
_, errVal = swag.ConvertInt64(stringRep)
436+
_, errVal = conv.ConvertInt64(stringRep)
437437
}
438438
case numberType:
439439
fallthrough
440440
default:
441441
switch format {
442442
case numberFormatFloat, numberFormatFloat32:
443-
_, errVal = swag.ConvertFloat32(stringRep)
443+
_, errVal = conv.ConvertFloat32(stringRep)
444444
case numberFormatDouble, numberFormatFloat64:
445445
fallthrough
446446
default:

0 commit comments

Comments
 (0)