Compare commits

...
3 Commits
2 changed files with 20 additions and 8 deletions

No files matched your search

+1 -1
View File
@@ -49,7 +49,7 @@ $ sj convert -u https://petstore.swagger.io/v2/swagger.json -o openapi.json`,
log.Error("Command not specified. See the --help flag for usage.")
}
},
Version: "2.0.0",
Version: "2.0.3",
}
func Execute() {
+19 -7
View File
@@ -98,7 +98,7 @@ func GenerateRequests(bodyBytes []byte, client http.Client) {
apiTarget = serverURL
} else {
basePath = serverURL
apiTarget = u.Scheme + "://" + u.Host + serverURL
apiTarget = u.Scheme + "://" + u.Host
}
}
}
@@ -181,7 +181,20 @@ func BuildRequestsFromPaths(spec map[string]interface{}, client http.Client) {
var pValue string
if propertyName, ok := properties[propertyItem].(map[string]interface{}); ok {
if exampleValue, ok := propertyName["example"]; ok {
pValue = exampleValue.(string)
switch ex := exampleValue.(type) {
case string:
pValue = exampleValue.(string)
case []interface{}:
if len(ex) > 0 {
if v, ok := ex[0].(string); ok {
pValue = v
} else {
pValue = "1"
}
}
default:
pValue = "1"
}
} else if propertyType, ok := propertyName["type"].(string); ok {
// Attempt to prevent version strings from being improperly supplied (i.e. v1)
if propertyType == "string" && propertyName["name"] != "version" {
@@ -192,7 +205,7 @@ func BuildRequestsFromPaths(spec map[string]interface{}, client http.Client) {
}
if strings.Contains(curl, "-d") {
if strings.Contains(curl, "-d '") {
bodyData += fmt.Sprintf("&%s=%s", propertyItem, pValue)
curl = strings.TrimSuffix(curl, "'")
curl += fmt.Sprintf("&%s=%s'", propertyItem, pValue)
@@ -200,7 +213,6 @@ func BuildRequestsFromPaths(spec map[string]interface{}, client http.Client) {
bodyData += fmt.Sprintf("%s=%s", propertyItem, pValue)
curl += fmt.Sprintf(" -d '%s=%s'", propertyItem, pValue)
}
}
}
}
@@ -229,7 +241,7 @@ func BuildRequestsFromPaths(spec map[string]interface{}, client http.Client) {
case "header":
curl += fmt.Sprintf(" -H \"%s: %s\"", name, pValue)
case "body":
if strings.Contains(curl, "-d") {
if strings.Contains(curl, "-d '") {
bodyData += fmt.Sprintf("&%s=%s", name, pValue)
curl = strings.TrimSuffix(curl, "'")
curl += fmt.Sprintf("&%s=%s'", name, pValue)
@@ -384,7 +396,7 @@ func BuildRequestsFromPaths(spec map[string]interface{}, client http.Client) {
jsonResultsStringArray = append(jsonResultsStringArray, ","+string(result))
}
if outputFormat == "console" {
writeLog(sc, basePath+logURL.Path, strings.ToUpper(method), errorDescriptions[sc], resp[:tempResponsePreviewLength])
writeLog(sc, logURL.Path, strings.ToUpper(method), errorDescriptions[sc], resp[:tempResponsePreviewLength])
}
}
} else {
@@ -394,7 +406,7 @@ func BuildRequestsFromPaths(spec map[string]interface{}, client http.Client) {
jsonResultsStringArray = append(jsonResultsStringArray, ","+string(result))
}
if outputFormat == "console" {
writeLog(sc, basePath+logURL.Path, strings.ToUpper(method), errorDescriptions[sc], resp[:tempResponsePreviewLength])
writeLog(sc, logURL.Path, strings.ToUpper(method), errorDescriptions[sc], resp[:tempResponsePreviewLength])
}
}