go.mod: Update oapi-codegen and kin-openapi

This commit is contained in:
sanne 2022-01-11 19:00:14 +01:00 committed by Sanne Raymaekers
parent add17bba45
commit a83cf95d5b
156 changed files with 29663 additions and 2248 deletions

View file

@ -63,7 +63,7 @@ iteration:
// Read our custom "multijson" tag that
// allows multiple fields with the same name.
if v := f.Tag.Get("multijson"); len(v) > 0 {
if v := f.Tag.Get("multijson"); v != "" {
field.MultipleFields = true
jsonTag = v
}
@ -74,11 +74,11 @@ iteration:
}
// Parse the tag
if len(jsonTag) > 0 {
if jsonTag != "" {
field.HasJSONTag = true
for i, part := range strings.Split(jsonTag, ",") {
if i == 0 {
if len(part) > 0 {
if part != "" {
field.JSONName = part
}
} else {
@ -92,12 +92,8 @@ iteration:
}
}
if _, ok := field.Type.MethodByName("MarshalJSON"); ok {
field.TypeIsMarshaller = true
}
if _, ok := field.Type.MethodByName("UnmarshalJSON"); ok {
field.TypeIsUnmarshaller = true
}
_, field.TypeIsMarshaller = field.Type.MethodByName("MarshalJSON")
_, field.TypeIsUnmarshaller = field.Type.MethodByName("UnmarshalJSON")
// Field is done
fields = append(fields, field)

View file

@ -59,11 +59,11 @@ func (encoder *ObjectEncoder) EncodeStructFieldsAndExtensions(value interface{})
// Follow "encoding/json" semantics
if reflection.Kind() != reflect.Ptr {
// Panic because this is a clear programming error
panic(fmt.Errorf("Value %s is not a pointer", reflection.Type().String()))
panic(fmt.Errorf("value %s is not a pointer", reflection.Type().String()))
}
if reflection.IsNil() {
// Panic because this is a clear programming error
panic(fmt.Errorf("Value %s is nil", reflection.Type().String()))
panic(fmt.Errorf("value %s is nil", reflection.Type().String()))
}
// Take the element
@ -146,7 +146,7 @@ iteration:
continue iteration
}
default:
panic(fmt.Errorf("Field '%s' has unsupported type %s", field.JSONName, field.Type.String()))
panic(fmt.Errorf("field %q has unsupported type %s", field.JSONName, field.Type.String()))
}
// No special treament is needed

View file

@ -25,7 +25,7 @@ type ObjectDecoder struct {
func NewObjectDecoder(data []byte) (*ObjectDecoder, error) {
var remainingFields map[string]json.RawMessage
if err := json.Unmarshal(data, &remainingFields); err != nil {
return nil, fmt.Errorf("Failed to unmarshal extension properties: %v\nInput: %s", err, data)
return nil, fmt.Errorf("failed to unmarshal extension properties: %v (%s)", err, data)
}
return &ObjectDecoder{
Data: data,
@ -41,10 +41,10 @@ func (decoder *ObjectDecoder) DecodeExtensionMap() map[string]json.RawMessage {
func (decoder *ObjectDecoder) DecodeStructFieldsAndExtensions(value interface{}) error {
reflection := reflect.ValueOf(value)
if reflection.Kind() != reflect.Ptr {
panic(fmt.Errorf("Value %T is not a pointer", value))
panic(fmt.Errorf("value %T is not a pointer", value))
}
if reflection.IsNil() {
panic(fmt.Errorf("Value %T is nil", value))
panic(fmt.Errorf("value %T is nil", value))
}
reflection = reflection.Elem()
for (reflection.Kind() == reflect.Interface || reflection.Kind() == reflect.Ptr) && !reflection.IsNil() {
@ -52,7 +52,7 @@ func (decoder *ObjectDecoder) DecodeStructFieldsAndExtensions(value interface{})
}
reflectionType := reflection.Type()
if reflectionType.Kind() != reflect.Struct {
panic(fmt.Errorf("Value %T is not a struct", value))
panic(fmt.Errorf("value %T is not a struct", value))
}
typeInfo := GetTypeInfo(reflectionType)
@ -87,7 +87,7 @@ func (decoder *ObjectDecoder) DecodeStructFieldsAndExtensions(value interface{})
continue
}
}
return fmt.Errorf("Error while unmarshalling property '%s' (%s): %v",
return fmt.Errorf("failed to unmarshal property %q (%s): %v",
field.JSONName, fieldValue.Type().String(), err)
}
if !isPtr {
@ -109,7 +109,7 @@ func (decoder *ObjectDecoder) DecodeStructFieldsAndExtensions(value interface{})
continue
}
}
return fmt.Errorf("Error while unmarshalling property '%s' (%s): %v",
return fmt.Errorf("failed to unmarshal property %q (%s): %v",
field.JSONName, fieldPtr.Type().String(), err)
}

View file

@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"sort"
"strings"
)
// UnsupportedPropertiesError is a helper for extensions that want to refuse
@ -27,7 +26,7 @@ func (err *UnsupportedPropertiesError) Error() string {
m := err.UnsupportedProperties
typeInfo := GetTypeInfoForValue(err.Value)
if m == nil || typeInfo == nil {
return "Invalid UnsupportedPropertiesError"
return fmt.Sprintf("invalid %T", *err)
}
keys := make([]string, 0, len(m))
for k := range m {
@ -36,10 +35,8 @@ func (err *UnsupportedPropertiesError) Error() string {
sort.Strings(keys)
supported := typeInfo.FieldNames()
if len(supported) == 0 {
return fmt.Sprintf("Type '%T' doesn't take any properties. Unsupported properties: '%s'\n",
err.Value, strings.Join(keys, "', '"))
return fmt.Sprintf("type \"%T\" doesn't take any properties. Unsupported properties: %+v",
err.Value, keys)
}
return fmt.Sprintf("Unsupported properties: '%s'\nSupported properties are: '%s'",
strings.Join(keys, "', '"),
strings.Join(supported, "', '"))
return fmt.Sprintf("unsupported properties: %+v (supported properties are: %+v)", keys, supported)
}