Skip to content

Commit 368327b

Browse files
authored
openapi3: remove deepcopy dependency (#1193)
1 parent 4dc207c commit 368327b

3 files changed

Lines changed: 21 additions & 6 deletions

File tree

‎go.mod‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ go 1.25
55
require (
66
github.com/go-openapi/jsonpointer v0.21.0
77
github.com/gorilla/mux v1.8.0
8-
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826
98
github.com/oasdiff/yaml v0.1.0
109
github.com/oasdiff/yaml3 v0.0.13
1110
github.com/perimeterx/marshmallow v1.1.5

‎go.sum‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
1818
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
1919
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
2020
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
21-
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
22-
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
2321
github.com/oasdiff/yaml v0.1.0 h1:0bqZjfKc/8S9urj4JuwepX41WX9EoA6ifhU3SV06cXg=
2422
github.com/oasdiff/yaml v0.1.0/go.mod h1:kOlRmMdL2X3vucLCEQO5u61SU22RysnfXvcttrZA1O0=
2523
github.com/oasdiff/yaml3 v0.0.13 h1:06svmvOHOVBqF81+sY2EUScvUI/iS/vl2VIeUUxZQwg=

‎openapi3/schema.go‎

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
"unicode/utf16"
1818

1919
"github.com/go-openapi/jsonpointer"
20-
"github.com/mohae/deepcopy"
2120
"github.com/woodsbury/decimal128"
2221
)
2322

@@ -2202,7 +2201,7 @@ func (schema *Schema) visitXOFOperations(settings *schemaValidationSettings, val
22022201

22032202
// make a deep copy to protect origin value from being injected default value that defined in mismatched oneOf schema
22042203
if settings.asreq || settings.asrep {
2205-
tempValue = deepcopy.Copy(value)
2204+
tempValue = deepCopyJSONValue(value)
22062205
}
22072206

22082207
if err := v.visitJSON(settings, tempValue); err != nil {
@@ -2265,7 +2264,7 @@ func (schema *Schema) visitXOFOperations(settings *schemaValidationSettings, val
22652264

22662265
// make a deep copy to protect origin value from being injected default value that defined in mismatched anyOf schema
22672266
if settings.asreq || settings.asrep {
2268-
tempValue = deepcopy.Copy(value)
2267+
tempValue = deepCopyJSONValue(value)
22692268
}
22702269
if err := v.visitJSON(settings, tempValue); err == nil {
22712270
ok = true
@@ -3158,6 +3157,25 @@ func unsupportedFormat(format string) error {
31583157
return fmt.Errorf("unsupported 'format' value %q", format)
31593158
}
31603159

3160+
func deepCopyJSONValue(v any) any {
3161+
switch v := v.(type) {
3162+
case map[string]any:
3163+
cp := make(map[string]any, len(v))
3164+
for k, val := range v {
3165+
cp[k] = deepCopyJSONValue(val)
3166+
}
3167+
return cp
3168+
case []any:
3169+
cp := make([]any, len(v))
3170+
for i, val := range v {
3171+
cp[i] = deepCopyJSONValue(val)
3172+
}
3173+
return cp
3174+
default:
3175+
return v // string, float64, bool, nil — all immutable
3176+
}
3177+
}
3178+
31613179
// UnmarshalJSON sets Schemas to a copy of data.
31623180
func (schemas *Schemas) UnmarshalJSON(data []byte) (err error) {
31633181
*schemas, err = unmarshalStringMapP[SchemaRef](data)

0 commit comments

Comments
 (0)