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 <vincent@sbr.pm>
This commit is contained in:
Vincent Demeester 2018-05-31 13:38:58 +02:00
parent a8ee42ad53
commit 6bcfa8806c
No known key found for this signature in database
GPG Key ID: 083CC6FD6EB699A3
3 changed files with 74 additions and 36 deletions

View File

@ -467,44 +467,44 @@ DoTuq9lAU9Q4O1xV/59X/w8AAP//zRo7vm9CAAA=
"/data/config_schema_v3.7.json": { "/data/config_schema_v3.7.json": {
local: "data/config_schema_v3.7.json", local: "data/config_schema_v3.7.json",
size: 17540, size: 17740,
modtime: 1518458244, modtime: 1518458244,
compressed: ` compressed: `
H4sIAAAAAAAC/+xcS2/jOBK++1cImrlNHg3sYBfbtz3uafe8gVugqbLNCUVyipQTT8P/faGnJYoUaVvp H4sIAAAAAAAC/+xcS4/bOBK++1cYmrlNPwLsYBeb2x73tHvehiPQVNnmNEVyipTTTuD/vtDTEkWKlK1O
ZDBpoNGJVHzUk18VS/19lSTpz5ruoSDp1yTdG6O+Pj7+pqW4b54+SNw95ki25v7Lr4/Ns5/Su2ocy6sh dzAdIEi3VHzUg8WvHsr31Xqd/KrpAXKSfF4nB2PU58fHP7QU9/XTB4n7xwzJztx/+v2xfvZLcleOY1k5
VIot22XNm+zwt4d/PFTDGxJzVFARyc1vQE3zDOH3kiFUg5/SA6BmUqTru1X1TqFUgIaBTr8m1eaSpCfp hEqxY/u0fpMe//bwj4dyeE1iTgpKIrn9A6ipnyH8WTCEcvBTcgTUTIpkc7cq3ymUCtAw0Mnndbm59boj
Hgym1QaZ2KX141M9Q5KkGv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at4S5i2guS5yWkFHXVyJLyIqIFc
fp4U0mlHtkCCFtN4FdUe1FJlUi1/PxFuAVqHq+NMkWKpCBvdMJU6E4aPEDvLjfCUnz927LybNkV6tPrU 1TXiyx1EDD47P2MK6bQlWyBAi2nQimojaqhSqZavY4RbhTbhLDpTJF/Kw0Y3ViXOgOE9+M5iKzxp6vft
F6Tuelmto1XsdYzl9l/XxuxLRVcRjRhD6D6q3nZh2eOGk2hSXneGqpbqM1JdEKn+7Hb942yw/dIy+DVf O+/GzZMerT51Cam7TlabaBV7D8Zy+69yY3bx0ZVEI8YQeojKt81Me/yA9OUoXe90aQ3Vh0eb4dF+dvt/
TRX+OPIGy4v4LOID6PWd1TU5DJ3qaqk+1fXe6rKaVQZqm16uzEkyuqN2NbxL6bdhkzn+fwNfBuPdlO+K f7bafOEZ/Iqwogp/lHmDhUZ8jvEO9P+TqHV0CTvV2lB9qPVnUavVdNNT77j4MyXx6M7gVb/W023DJnP8
z1q0FeI85wueHw+/zCDFuc73N4JYC7QJunVqlShWfVOg/Xm2P0Z04ycfa1d8iuPk8u/7uDGk+dB6PZKP Pw2+CMu7KV+p0lq0EfY05wveWw+/TSDZqQ7+V4KAC7Q7unVqpVBWXXOj/Zm535e040cfnZd8itOoOPl9
RdJ8cDI4sNdRia/rE267LaX7lNrTKTfODlfV39Pq/wEAAP//il2qfYREAAA= 2OBSfzC+GcjHIqk/nOkBhU1UYO76FN1ur2k/Cfd0/A2j11X597z6fwAAAP//5FICNUxFAAA=
`, `,
}, },

View File

@ -319,6 +319,7 @@
}, },
"working_dir": {"type": "string"} "working_dir": {"type": "string"}
}, },
"patternProperties": {"^x-": {}},
"additionalProperties": false "additionalProperties": false
}, },
@ -489,6 +490,7 @@
"attachable": {"type": "boolean"}, "attachable": {"type": "boolean"},
"labels": {"$ref": "#/definitions/list_or_dict"} "labels": {"$ref": "#/definitions/list_or_dict"}
}, },
"patternProperties": {"^x-": {}},
"additionalProperties": false "additionalProperties": false
}, },
@ -513,6 +515,7 @@
}, },
"labels": {"$ref": "#/definitions/list_or_dict"} "labels": {"$ref": "#/definitions/list_or_dict"}
}, },
"patternProperties": {"^x-": {}},
"additionalProperties": false "additionalProperties": false
}, },
@ -530,6 +533,7 @@
}, },
"labels": {"$ref": "#/definitions/list_or_dict"} "labels": {"$ref": "#/definitions/list_or_dict"}
}, },
"patternProperties": {"^x-": {}},
"additionalProperties": false "additionalProperties": false
}, },
@ -547,6 +551,7 @@
}, },
"labels": {"$ref": "#/definitions/list_or_dict"} "labels": {"$ref": "#/definitions/list_or_dict"}
}, },
"patternProperties": {"^x-": {}},
"additionalProperties": false "additionalProperties": false
}, },

View File

@ -45,6 +45,39 @@ func TestValidateAllowsXTopLevelFields(t *testing.T) {
assert.NilError(t, err) 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) { func TestValidateSecretConfigNames(t *testing.T) {
config := dict{ config := dict{
"version": "3.5", "version": "3.5",