|
8 | 8 | "net/http"
|
9 | 9 | "os"
|
10 | 10 | "path/filepath"
|
| 11 | + "strconv" |
11 | 12 | "strings"
|
12 | 13 | "time"
|
13 | 14 |
|
@@ -44,9 +45,7 @@ func (c *configCommand) executeVerify(cmd *cobra.Command, _ []string) error {
|
44 | 45 | return fmt.Errorf("[%s] validate: %w", usedConfigFile, err)
|
45 | 46 | }
|
46 | 47 |
|
47 |
| - detail := v.DetailedOutput() |
48 |
| - |
49 |
| - printValidationDetail(cmd, detail) |
| 48 | + printValidationDetail(cmd, v.DetailedOutput()) |
50 | 49 |
|
51 | 50 | return errors.New("the configuration contains invalid elements")
|
52 | 51 | }
|
@@ -102,11 +101,10 @@ func createSchemaURL(flags *pflag.FlagSet, buildInfo BuildInfo) (string, error)
|
102 | 101 |
|
103 | 102 | func validateConfiguration(schemaPath, targetFile string) error {
|
104 | 103 | compiler := jsonschema.NewCompiler()
|
105 |
| - loader := jsonschema.SchemeURLLoader{ |
| 104 | + compiler.UseLoader(jsonschema.SchemeURLLoader{ |
106 | 105 | "file": jsonschema.FileLoader{},
|
107 | 106 | "https": newJSONSchemaHTTPLoader(),
|
108 |
| - } |
109 |
| - compiler.UseLoader(loader) |
| 107 | + }) |
110 | 108 | compiler.DefaultDraft(jsonschema.Draft7)
|
111 | 109 |
|
112 | 110 | schema, err := compiler.Compile(schemaPath)
|
@@ -139,9 +137,11 @@ func validateConfiguration(schemaPath, targetFile string) error {
|
139 | 137 |
|
140 | 138 | func printValidationDetail(cmd *cobra.Command, detail *jsonschema.OutputUnit) {
|
141 | 139 | if detail.Error != nil {
|
142 |
| - b, _ := json.Marshal(detail.Error) |
| 140 | + data, _ := json.Marshal(detail.Error) |
| 141 | + details, _ := strconv.Unquote(string(data)) |
| 142 | + |
143 | 143 | cmd.PrintErrf("jsonschema: %q does not validate with %q: %s\n",
|
144 |
| - strings.ReplaceAll(strings.TrimPrefix(detail.InstanceLocation, "/"), "/", "."), detail.KeywordLocation, b) |
| 144 | + strings.ReplaceAll(strings.TrimPrefix(detail.InstanceLocation, "/"), "/", "."), detail.KeywordLocation, details) |
145 | 145 | }
|
146 | 146 |
|
147 | 147 | for _, d := range detail.Errors {
|
|
0 commit comments