From 6bcfa8806c12637d7956ef8ffc4e3020a0cd1be7 Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Thu, 31 May 2018 13:38:58 +0200 Subject: [PATCH] Allow `x-*` extension on 3rd level objects As for top-level key, any 3rd-level key which starts with `x-` will be ignored by compose. This allows for users to: * include additional metadata in their compose files * create YAML anchor objects that can be re-used in other parts of the config This matches a similar feature in the swagger spec definition: https://swagger.io/specification/#specificationExtensions This means a composefile like the following is valid ``` verison: "3.7" services: foo: image: foo/bar x-foo: bar network: bar: x-bar: baz ``` It concerns services, volumes, networks, configs and secrets. Signed-off-by: Vincent Demeester --- cli/compose/schema/bindata.go | 72 +++++++++---------- .../schema/data/config_schema_v3.7.json | 5 ++ cli/compose/schema/schema_test.go | 33 +++++++++ 3 files changed, 74 insertions(+), 36 deletions(-) diff --git a/cli/compose/schema/bindata.go b/cli/compose/schema/bindata.go index 9649d03070..e56e243201 100644 --- a/cli/compose/schema/bindata.go +++ b/cli/compose/schema/bindata.go @@ -467,44 +467,44 @@ DoTuq9lAU9Q4O1xV/59X/w8AAP//zRo7vm9CAAA= "/data/config_schema_v3.7.json": { local: "data/config_schema_v3.7.json", - size: 17540, + size: 17740, modtime: 1518458244, compressed: ` -H4sIAAAAAAAC/+xcS2/jOBK++1cImrlNHg3sYBfbtz3uafe8gVugqbLNCUVyipQTT8P/faGnJYoUaVvp -ZDBpoNGJVHzUk18VS/19lSTpz5ruoSDp1yTdG6O+Pj7+pqW4b54+SNw95ki25v7Lr4/Ns5/Su2ocy6sh -VIot22XNm+zwt4d/PFTDGxJzVFARyc1vQE3zDOH3kiFUg5/SA6BmUqTru1X1TqFUgIaBTr8m1eaSpCfp -Hgym1QaZ2KX141M9Q5KkGvDA6GCGfqs/PZ7nf+zJ7uxZB5utnytiDKD473Rv9etvT+T+j3/d/+/L/T8f -svv1Lz+PXlfyRdg2y+ewZYIZJkW/ftpTntqfTv3CJM9rYsJHa28J1zDmWYB5kfgc4rkneyee2/UdPI/Z -OUheF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DnzTYMzLdaxHqg2CabK2KkQvZlAaFRzfACiM0BIPMKv202LUP +sUC/zwKJYTnIwlwLTwma+QDX7ijrta20pZYpE+pR2hb01Csk1mmXoJnE4BEQWVXiigIvCIozSnQIIN6Q +5EfJ+ZbQ57Rpf5oDyifQuCJIOAfOdB6DbpMMODldZTl1rYowXiCkhEaURBpdCWYkXr9kTl7SdtmKJHBu +63OKGfjWBFHdMza+rE/G/Y6hNnUaQqrmt6H7P3tTO7HVgMvVoTJi4MMkPkyin6GrYgO9lDk4kwDLdPip +IrZekeSQy1CDx+0pf0vlCLqECb4C5HsRgIN6DwKQ0XRgDZ4rZ0z7SlWU2y27xh6SszrEXMK8qRT1PmI8 +z42urvQ7JRDPldFRrvUrE5n8Oh9mLSBtxQkFC5rdKmhtkDBhZvcq2GJRCDtAEBQmj+U4ZzSRN1ouIa8Q +SPYGJaNblX/DdwNOdzOF58cDRoHhUHsOrfm1NdFQmDFNEQx0K3d9iat4S5i2guS5yWkFHXVyJLyIqIFc +1TXiyx1EDD47P2MK6bQlWyBAi2nQimojaqhSqZavY4RbhTbhLDpTJF/Kw0Y3ViXOgOE9+M5iKzxp6vft +O+/GzZMerT51Cam7TlabaBV7D8Zy+69yY3bx0ZVEI8YQeojKt81Me/yA9OUoXe90aQ3Vh0eb4dF+dvt/ +f7bafOEZ/Iqwogp/lHmDhUZ8jvEO9P+TqHV0CTvV2lB9qPVnUavVdNNT77j4MyXx6M7gVb/W023DJnP8 +Pw2+CMu7KV+p0lq0EfY05wveWw+/TSDZqQ7+V4KAC7Q7unVqpVBWXXOj/Zm535e040cfnZd8itOoOPl9 +2OBSfzC+GcjHIqk/nOkBhU1UYO76FN1ur2k/Cfd0/A2j11X597z6fwAAAP//5FICNUxFAAA= `, }, diff --git a/cli/compose/schema/data/config_schema_v3.7.json b/cli/compose/schema/data/config_schema_v3.7.json index 4c3d24dcd2..05566cf819 100644 --- a/cli/compose/schema/data/config_schema_v3.7.json +++ b/cli/compose/schema/data/config_schema_v3.7.json @@ -319,6 +319,7 @@ }, "working_dir": {"type": "string"} }, + "patternProperties": {"^x-": {}}, "additionalProperties": false }, @@ -489,6 +490,7 @@ "attachable": {"type": "boolean"}, "labels": {"$ref": "#/definitions/list_or_dict"} }, + "patternProperties": {"^x-": {}}, "additionalProperties": false }, @@ -513,6 +515,7 @@ }, "labels": {"$ref": "#/definitions/list_or_dict"} }, + "patternProperties": {"^x-": {}}, "additionalProperties": false }, @@ -530,6 +533,7 @@ }, "labels": {"$ref": "#/definitions/list_or_dict"} }, + "patternProperties": {"^x-": {}}, "additionalProperties": false }, @@ -547,6 +551,7 @@ }, "labels": {"$ref": "#/definitions/list_or_dict"} }, + "patternProperties": {"^x-": {}}, "additionalProperties": false }, diff --git a/cli/compose/schema/schema_test.go b/cli/compose/schema/schema_test.go index c029f2f725..17ffb203f6 100644 --- a/cli/compose/schema/schema_test.go +++ b/cli/compose/schema/schema_test.go @@ -45,6 +45,39 @@ func TestValidateAllowsXTopLevelFields(t *testing.T) { assert.NilError(t, err) } +func TestValidateAllowsXFields(t *testing.T) { + config := dict{ + "version": "3.7", + "services": dict{ + "bar": dict{ + "x-extra-stuff": dict{}, + }, + }, + "volumes": dict{ + "bar": dict{ + "x-extra-stuff": dict{}, + }, + }, + "networks": dict{ + "bar": dict{ + "x-extra-stuff": dict{}, + }, + }, + "configs": dict{ + "bar": dict{ + "x-extra-stuff": dict{}, + }, + }, + "secrets": dict{ + "bar": dict{ + "x-extra-stuff": dict{}, + }, + }, + } + err := Validate(config, "3.7") + assert.NilError(t, err) +} + func TestValidateSecretConfigNames(t *testing.T) { config := dict{ "version": "3.5",