This commit is contained in:
dayterr
2025-12-23 17:39:58 +03:00
parent 055b256d6b
commit f111bf25fc
35 changed files with 251 additions and 111 deletions

View File

@@ -33,57 +33,101 @@ func getParameters(input map[string]interface{}) []interface{} {
return emptySlice
}
params, ok := parameters["parameters"]
if !ok {
return emptySlice
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
var schemaData map[string]interface{}
var found bool
if formData, ok := content["application/x-www-form-urlencoded"].(map[string]interface{}); ok {
if schema, ok := formData["schema"].(map[string]interface{}); ok {
schemaData = schema
found = true
}
} else if jsonData, ok := content["application/json"].(map[string]interface{}); ok {
if schema, ok := jsonData["schema"].(map[string]interface{}); ok {
schemaData = schema
found = true
}
} else if multipartData, ok := content["multipart/form-data"].(map[string]interface{}); ok {
if schema, ok := multipartData["schema"].(map[string]interface{}); ok {
schemaData = schema
found = true
}
}
if found && schemaData != nil {
if properties, ok := schemaData["properties"].(map[string]interface{}); ok {
requiredFields := make(map[string]bool)
if req, ok := schemaData["required"].([]interface{}); ok {
for _, r := range req {
if reqStr, ok := r.(string); ok {
requiredFields[reqStr] = true
}
}
}
for name, prop := range properties {
propMap, ok := prop.(map[string]interface{})
if !ok {
continue
}
newParam := make(map[string]interface{})
newParam["name"] = name
if propType, ok := propMap["type"].(string); ok {
newParam["type"] = propType
}
newParam["required"] = requiredFields[name]
if propType, ok := propMap["type"].(string); ok && propType == "array" {
if items, ok := propMap["items"].(map[string]interface{}); ok {
newParam["items"] = items
}
}
result = append(result, newParam)
}
}
}
}
}
res, ok := params.([]interface{})
if !ok {
return emptySlice
}
// Check if there's a body parameter
for _, p := range res {
param, ok := p.(map[string]interface{})
if !ok {
continue
}
if param["name"] == "body" {
schema, ok := param["schema"].(map[string]interface{})
if params, ok := parameters["parameters"].([]interface{}); ok {
for _, p := range params {
param, ok := p.(map[string]interface{})
if !ok {
continue
}
properties, ok := schema["properties"].(map[string]interface{})
if !ok {
continue
}
requiredFields := make(map[string]bool)
if req, ok := schema["required"].([]interface{}); ok {
for _, r := range req {
requiredFields[r.(string)] = true
}
}
var newParams []interface{}
for name, prop := range properties {
propMap, ok := prop.(map[string]interface{})
if !ok {
continue
}
newParam := make(map[string]interface{})
newParam := make(map[string]interface{})
if name, ok := param["name"].(string); ok {
newParam["name"] = name
newParam["type"] = propMap["type"]
newParam["required"] = requiredFields[name]
if propMap["type"] == "array" {
if items, ok := propMap["items"].(map[string]interface{}); ok {
}
if schema, ok := param["schema"].(map[string]interface{}); ok {
if paramType, ok := schema["type"].(string); ok {
newParam["type"] = paramType
}
if paramType, ok := schema["type"].(string); ok && paramType == "array" {
if items, ok := schema["items"].(map[string]interface{}); ok {
newParam["items"] = items
}
}
newParams = append(newParams, newParam)
}
return newParams
// Handle required field
if required, ok := param["required"].(bool); ok {
newParam["required"] = required
} else {
newParam["required"] = false
}
result = append(result, newParam)
}
}
return res
if len(result) > 0 {
return result
}
return emptySlice
}
func getBytesFromJSON(fileName string, t *testing.T) []byte {