Skip to content

Commit 25fe179

Browse files
jhrotkoglours
authored andcommitted
Fix compose schema
Signed-off-by: Joana Hrotko <[email protected]>
1 parent 94bd735 commit 25fe179

File tree

9 files changed

+582
-282
lines changed

9 files changed

+582
-282
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,6 @@ check-license: build-validate-image
4646
setup: ## Setup the precommit hook
4747
@which pre-commit > /dev/null 2>&1 || (echo "pre-commit not installed see README." && false)
4848
@pre-commit install
49+
50+
.PHONY: validate
51+
validate: lint test check-license

consts/consts.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ const (
2727
const Extensions = "#extensions" // Using # prefix, we prevent risk to conflict with an actual yaml key
2828

2929
type ComposeFileKey struct{}
30+
type ComposeSchema struct{}

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ require (
1111
github.com/mitchellh/copystructure v1.2.0
1212
github.com/mitchellh/mapstructure v1.5.0
1313
github.com/opencontainers/go-digest v1.0.0
14+
github.com/santhosh-tekuri/jsonschema v1.2.4
1415
github.com/sirupsen/logrus v1.9.0
1516
github.com/stretchr/testify v1.8.4
16-
github.com/xeipuuv/gojsonschema v1.2.0
1717
golang.org/x/exp v0.0.0-20240112132812-db7319d0e0e3
1818
golang.org/x/sync v0.3.0
1919
gopkg.in/yaml.v3 v3.0.1
@@ -24,7 +24,5 @@ require (
2424
github.com/davecgh/go-spew v1.1.1 // indirect
2525
github.com/mitchellh/reflectwalk v1.0.2 // indirect
2626
github.com/pmezard/go-difflib v1.0.0 // indirect
27-
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f // indirect
28-
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
2927
golang.org/x/sys v0.1.0 // indirect
3028
)

go.sum

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,14 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
2222
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
2323
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
2424
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
25+
github.com/santhosh-tekuri/jsonschema v1.2.4 h1:hNhW8e7t+H1vgY+1QeEQpveR6D4+OwKPXCfD2aieJis=
26+
github.com/santhosh-tekuri/jsonschema v1.2.4/go.mod h1:TEAUOeZSmIxTTuHatJzrvARHiuO9LYd+cIxzgEHCQI4=
2527
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
2628
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
2729
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
28-
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
2930
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
3031
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
3132
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
32-
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f h1:J9EGpcZtP0E/raorCMxlFGSTBrsSlaDGf3jU/qvAE2c=
33-
github.com/xeipuuv/gojsonpointer v0.0.0-20180127040702-4e3ac2762d5f/go.mod h1:N2zxlSyiKSe5eX1tZViRH5QA0qijqEDrYZiPEAiq3wU=
34-
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHovont7NscjpAxXsDA8S8BMYve8Y5+7cuRE7R0=
35-
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
36-
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
37-
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
3833
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
3934
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
4035
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=

loader/loader.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ func Load(configDetails types.ConfigDetails, options ...func(*Options)) (*types.
309309
// LoadWithContext reads a ConfigDetails and returns a fully loaded configuration as a compose-go Project
310310
func LoadWithContext(ctx context.Context, configDetails types.ConfigDetails, options ...func(*Options)) (*types.Project, error) {
311311
opts := toOptions(&configDetails, options)
312+
312313
dict, err := loadModelWithContext(ctx, &configDetails, opts)
313314
if err != nil {
314315
return nil, err
@@ -366,6 +367,11 @@ func loadYamlModel(ctx context.Context, config types.ConfigDetails, opts *Option
366367
dict = map[string]interface{}{}
367368
err error
368369
)
370+
sch, err := schema.CreateComposeSchema()
371+
if err != nil {
372+
return nil, fmt.Errorf("could not initialise schema: %w", err)
373+
}
374+
369375
for _, file := range config.ConfigFiles {
370376
fctx := context.WithValue(ctx, consts.ComposeFileKey{}, file.Filename)
371377
if file.Content == nil && file.Config == nil {
@@ -427,7 +433,7 @@ func loadYamlModel(ctx context.Context, config types.ConfigDetails, opts *Option
427433
}
428434

429435
if !opts.SkipValidation {
430-
if err := schema.Validate(dict); err != nil {
436+
if err := sch.Validate(dict); err != nil {
431437
return fmt.Errorf("validating %s: %w", file.Filename, err)
432438
}
433439
if _, ok := dict["version"]; ok {

0 commit comments

Comments
 (0)