v1.13.3
This commit is contained in:
@@ -9,6 +9,31 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// extractTypeFromSchema extracts type from schema, handling oneOf cases
|
||||
// When oneOf contains a type and null, it returns the non-null type
|
||||
func extractTypeFromSchema(schema map[string]interface{}) string {
|
||||
// Check for direct type
|
||||
if paramType, ok := schema["type"].(string); ok {
|
||||
return paramType
|
||||
}
|
||||
|
||||
// Check for oneOf
|
||||
if oneOf, ok := schema["oneOf"].([]interface{}); ok {
|
||||
for _, item := range oneOf {
|
||||
if itemMap, ok := item.(map[string]interface{}); ok {
|
||||
if itemType, ok := itemMap["type"].(string); ok {
|
||||
// Skip null type, return the first non-null type found
|
||||
if itemType != "null" {
|
||||
return itemType
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
|
||||
func getParameters(input map[string]interface{}) []interface{} {
|
||||
var emptySlice []interface{}
|
||||
methods := []string{"get", "post", "put", "delete", "patch", "head", "options"}
|
||||
@@ -35,7 +60,6 @@ func getParameters(input map[string]interface{}) []interface{} {
|
||||
|
||||
var result []interface{}
|
||||
|
||||
//Check for requestBody
|
||||
if requestBody, ok := parameters["requestBody"].(map[string]interface{}); ok {
|
||||
if content, ok := requestBody["content"].(map[string]interface{}); ok {
|
||||
// Check for application/x-www-form-urlencoded, application/json, or multipart/form-data
|
||||
@@ -76,13 +100,27 @@ func getParameters(input map[string]interface{}) []interface{} {
|
||||
}
|
||||
newParam := make(map[string]interface{})
|
||||
newParam["name"] = name
|
||||
if propType, ok := propMap["type"].(string); ok {
|
||||
propType := extractTypeFromSchema(propMap)
|
||||
if propType != "" {
|
||||
newParam["type"] = propType
|
||||
}
|
||||
newParam["required"] = requiredFields[name]
|
||||
if propType, ok := propMap["type"].(string); ok && propType == "array" {
|
||||
if propType == "array" {
|
||||
// Try to get items from propMap first
|
||||
if items, ok := propMap["items"].(map[string]interface{}); ok {
|
||||
newParam["items"] = items
|
||||
} else if oneOf, ok := propMap["oneOf"].([]interface{}); ok {
|
||||
// If items not in propMap, try to get from oneOf array element
|
||||
for _, item := range oneOf {
|
||||
if itemMap, ok := item.(map[string]interface{}); ok {
|
||||
if itemType, ok := itemMap["type"].(string); ok && itemType == "array" {
|
||||
if items, ok := itemMap["items"].(map[string]interface{}); ok {
|
||||
newParam["items"] = items
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
result = append(result, newParam)
|
||||
@@ -104,12 +142,24 @@ func getParameters(input map[string]interface{}) []interface{} {
|
||||
newParam["name"] = name
|
||||
}
|
||||
if schema, ok := param["schema"].(map[string]interface{}); ok {
|
||||
if paramType, ok := schema["type"].(string); ok {
|
||||
paramType := extractTypeFromSchema(schema)
|
||||
if paramType != "" {
|
||||
newParam["type"] = paramType
|
||||
}
|
||||
if paramType, ok := schema["type"].(string); ok && paramType == "array" {
|
||||
if paramType == "array" {
|
||||
if items, ok := schema["items"].(map[string]interface{}); ok {
|
||||
newParam["items"] = items
|
||||
} else if oneOf, ok := schema["oneOf"].([]interface{}); ok {
|
||||
for _, item := range oneOf {
|
||||
if itemMap, ok := item.(map[string]interface{}); ok {
|
||||
if itemType, ok := itemMap["type"].(string); ok && itemType == "array" {
|
||||
if items, ok := itemMap["items"].(map[string]interface{}); ok {
|
||||
newParam["items"] = items
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user