mirror of
https://github.com/LukeHagar/libopenapi.git
synced 2025-12-10 04:20:24 +00:00
Added in high document API
filling out documentation, looking at DX and how to consume things, re-shuffling and cleaning house.
This commit is contained in:
49
utils/type_check.go
Normal file
49
utils/type_check.go
Normal file
@@ -0,0 +1,49 @@
|
||||
// Copyright 2022 Princess B33f Heavy Industries / Dave Shanley
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package utils
|
||||
|
||||
import "fmt"
|
||||
|
||||
// AreValuesCorrectlyTyped will look through an array of unknown values and check they match
|
||||
// against the supplied type as a string. The return value is empty if everything is OK, or it
|
||||
// contains failures in the form of a value as a key and a message as to why it's not valid
|
||||
func AreValuesCorrectlyTyped(valType string, values interface{}) map[string]string {
|
||||
var arr []interface{}
|
||||
if _, ok := values.([]interface{}); !ok {
|
||||
return nil
|
||||
}
|
||||
arr = values.([]interface{})
|
||||
|
||||
results := make(map[string]string)
|
||||
for _, v := range arr {
|
||||
switch v.(type) {
|
||||
case string:
|
||||
if valType != "string" {
|
||||
results[v.(string)] = fmt.Sprintf("enum value '%v' is a "+
|
||||
"string, but it's defined as a '%v'", v, valType)
|
||||
}
|
||||
case int64:
|
||||
if valType != "integer" && valType != "number" {
|
||||
results[fmt.Sprintf("%v", v)] = fmt.Sprintf("enum value '%v' is a "+
|
||||
"integer, but it's defined as a '%v'", v, valType)
|
||||
}
|
||||
case int:
|
||||
if valType != "integer" && valType != "number" {
|
||||
results[fmt.Sprintf("%v", v)] = fmt.Sprintf("enum value '%v' is a "+
|
||||
"integer, but it's defined as a '%v'", v, valType)
|
||||
}
|
||||
case float64:
|
||||
if valType != "number" {
|
||||
results[fmt.Sprintf("%v", v)] = fmt.Sprintf("enum value '%v' is a "+
|
||||
"number, but it's defined as a '%v'", v, valType)
|
||||
}
|
||||
case bool:
|
||||
if valType != "boolean" {
|
||||
results[fmt.Sprintf("%v", v)] = fmt.Sprintf("enum value '%v' is a "+
|
||||
"boolean, but it's defined as a '%v'", v, valType)
|
||||
}
|
||||
}
|
||||
}
|
||||
return results
|
||||
}
|
||||
Reference in New Issue
Block a user