diff --git a/references/cli/addon.go b/references/cli/addon.go index ccfa20c39..f7cdeedcd 100644 --- a/references/cli/addon.go +++ b/references/cli/addon.go @@ -18,6 +18,7 @@ package cli import ( "context" + "encoding/json" "fmt" "os" "path/filepath" @@ -753,12 +754,13 @@ func printSchema(ref *openapi3.Schema, currentParams map[string]interface{}, ind } required := required[propKey] + // Extra indentation on nested objects + addedIndent := addIndent(indent) + var currentValue string thisParam, hasParam := currentParams[propKey] if hasParam { - // Only show default parameter when it is a string, int, float, or bool - // We don't care about object's default values (they have no defaults anyway). - currentValue = fmt.Sprint(thisParam) + currentValue = fmt.Sprintf("%#v", thisParam) switch thisParam.(type) { case int: case int64: @@ -768,13 +770,12 @@ func printSchema(ref *openapi3.Schema, currentParams map[string]interface{}, ind case string: case bool: default: - currentValue = "" + if js, err := json.MarshalIndent(thisParam, "", " "); err == nil { + currentValue = strings.ReplaceAll(string(js), "\n", "\n\t "+addedIndent) + } } } - // Extra indentation on nested objects - addedIndent := addIndent(indent) - // Header: addon: description ret += addedIndent ret += color.New(color.FgCyan).Sprintf("-> ") @@ -783,8 +784,8 @@ func printSchema(ref *openapi3.Schema, currentParams map[string]interface{}, ind // Show current value if currentValue != "" { - ret += addIndent(indent) - ret += "\tcurrent: " + color.New(color.FgGreen).Sprintf("%#v\n", currentValue) + ret += addedIndent + ret += "\tcurrent: " + color.New(color.FgGreen).Sprintf("%s\n", currentValue) } // Show default value if defaultValue != "" {