Validate uses the jsonschema to validate the configuration
(config map[string]any, version string)
| 76 | |
| 77 | // Validate uses the jsonschema to validate the configuration |
| 78 | func Validate(config map[string]any, version string) error { |
| 79 | version = normalizeVersion(version) |
| 80 | schemaData, err := schemas.ReadFile("data/config_schema_v" + version + ".json") |
| 81 | if err != nil { |
| 82 | return fmt.Errorf("unsupported Compose file version: %s", version) |
| 83 | } |
| 84 | |
| 85 | schemaLoader := gojsonschema.NewStringLoader(string(schemaData)) |
| 86 | dataLoader := gojsonschema.NewGoLoader(config) |
| 87 | |
| 88 | result, err := gojsonschema.Validate(schemaLoader, dataLoader) |
| 89 | if err != nil { |
| 90 | return err |
| 91 | } |
| 92 | |
| 93 | if !result.Valid() { |
| 94 | return toError(result) |
| 95 | } |
| 96 | |
| 97 | return nil |
| 98 | } |
| 99 | |
| 100 | func toError(result *gojsonschema.Result) error { |
| 101 | err := getMostSpecificError(result.Errors()) |
searching dependent graphs…