@ -263,28 +263,28 @@ func MustString(value any) string {
}
}
func TryFix ValueType ( paramName string , schemaRef * openapi3 . SchemaRef , value any ) ( any , error ) {
func TryCorrect ValueType ( paramName string , schemaRef * openapi3 . SchemaRef , value any ) ( any , error ) {
if value == nil {
return "" , fmt . Errorf ( "value of '%s' is nil" , paramName )
}
switch schemaRef . Value . Type {
case openapi3 . TypeString :
return tryString ( value )
return tryCorrect String ( value )
case openapi3 . TypeNumber :
return tryFloat64 ( value )
return tryCorrect Float64 ( value )
case openapi3 . TypeInteger :
return tryInt64 ( value )
return tryCorrect Int64 ( value )
case openapi3 . TypeBoolean :
return tryBool ( value )
return tryCorrect Bool ( value )
case openapi3 . TypeArray :
arrVal , ok := value . ( [ ] any )
if ! ok {
return nil , fmt . Errorf ( "[TryFix ValueType] value '%s' is not array" , paramName )
return nil , fmt . Errorf ( "[TryCorrect ValueType] value '%s' is not array" , paramName )
}
for i , v := range arrVal {
_v , err := TryFix ValueType ( paramName , schemaRef . Value . Items , v )
_v , err := TryCorrect ValueType ( paramName , schemaRef . Value . Items , v )
if err != nil {
return nil , err
}
@ -296,7 +296,7 @@ func TryFixValueType(paramName string, schemaRef *openapi3.SchemaRef, value any)
case openapi3 . TypeObject :
mapVal , ok := value . ( map [ string ] any )
if ! ok {
return nil , fmt . Errorf ( "[TryFix ValueType] value '%s' is not object" , paramName )
return nil , fmt . Errorf ( "[TryCorrect ValueType] value '%s' is not object" , paramName )
}
for k , v := range mapVal {
@ -305,7 +305,7 @@ func TryFixValueType(paramName string, schemaRef *openapi3.SchemaRef, value any)
continue
}
_v , err := TryFix ValueType ( k , p , v )
_v , err := TryCorrect ValueType ( k , p , v )
if err != nil {
return nil , err
}
@ -315,11 +315,11 @@ func TryFixValueType(paramName string, schemaRef *openapi3.SchemaRef, value any)
return mapVal , nil
default :
return nil , fmt . Errorf ( "[TryFix ValueType] unsupported schema type '%s'" , schemaRef . Value . Type )
return nil , fmt . Errorf ( "[TryCorrect ValueType] unsupported schema type '%s'" , schemaRef . Value . Type )
}
}
func tryString ( value any ) ( string , error ) {
func tryCorrect String ( value any ) ( string , error ) {
switch val := value . ( type ) {
case string :
return val , nil
@ -331,11 +331,15 @@ func tryString(value any) (string, error) {
case json . Number :
return val . String ( ) , nil
default :
return "" , fmt . Errorf ( "cannot convert type from '%T' to string" , val )
b , err := sonic . MarshalString ( value )
if err != nil {
return "" , fmt . Errorf ( "tryCorrectString failed, err=%w" , err )
}
return b , nil
}
}
func tryInt64 ( value any ) ( int64 , error ) {
func tryCorrect Int64 ( value any ) ( int64 , error ) {
switch val := value . ( type ) {
case string :
vi64 , _ := strconv . ParseInt ( val , 10 , 64 )
@ -352,7 +356,7 @@ func tryInt64(value any) (int64, error) {
}
}
func tryBool ( value any ) ( bool , error ) {
func tryCorrect Bool ( value any ) ( bool , error ) {
switch val := value . ( type ) {
case string :
return strconv . ParseBool ( val )
@ -363,7 +367,7 @@ func tryBool(value any) (bool, error) {
}
}
func tryFloat64 ( value any ) ( float64 , error ) {
func tryCorrect Float64 ( value any ) ( float64 , error ) {
switch val := value . ( type ) {
case string :
return strconv . ParseFloat ( val , 64 )