@@ -19,6 +19,7 @@ package schema
1919import (
2020 // Enable support for embedded static resources
2121 _ "embed"
22+ "encoding/json"
2223 "errors"
2324 "fmt"
2425 "slices"
@@ -48,11 +49,11 @@ var Schema string
4849// Validate uses the jsonschema to validate the configuration
4950func Validate (config map [string ]interface {}) error {
5051 compiler := jsonschema .NewCompiler ()
51- json , err := jsonschema .UnmarshalJSON (strings .NewReader (Schema ))
52+ shema , err := jsonschema .UnmarshalJSON (strings .NewReader (Schema ))
5253 if err != nil {
5354 return err
5455 }
55- err = compiler .AddResource ("compose-spec.json" , json )
56+ err = compiler .AddResource ("compose-spec.json" , shema )
5657 if err != nil {
5758 return err
5859 }
@@ -61,7 +62,21 @@ func Validate(config map[string]interface{}) error {
6162 Validate : durationFormatChecker ,
6263 })
6364 schema := compiler .MustCompile ("compose-spec.json" )
64- err = schema .Validate (config )
65+
66+ // santhosh-tekuri doesn't allow derived types
67+ // see https://github.com/santhosh-tekuri/jsonschema/pull/240
68+ marshaled , err := json .Marshal (config )
69+ if err != nil {
70+ return err
71+ }
72+
73+ var raw map [string ]interface {}
74+ err = json .Unmarshal (marshaled , & raw )
75+ if err != nil {
76+ return err
77+ }
78+
79+ err = schema .Validate (raw )
6580 var verr * jsonschema.ValidationError
6681 if ok := errors .As (err , & verr ); ok {
6782 return validationError {getMostSpecificError (verr )}
0 commit comments