summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoffrey F <joffrey@docker.com>2017-08-25 18:09:06 -0700
committerJoffrey F <f.joffrey@gmail.com>2017-10-17 17:20:00 -0700
commit8c6f2217c45dd004b4fa10cca1cc7023a6f241ea (patch)
tree0edb4c6fe5cc85278c714f35856fac7a8530d662
parent42aa1c34475f121dbc0710312a6645ee1cc11a9a (diff)
Add support for extension fields in v2.x and v3.4
Signed-off-by: Joffrey F <joffrey@docker.com>
-rw-r--r--compose/config/config_schema_v2.0.json1
-rw-r--r--compose/config/config_schema_v2.1.json1
-rw-r--r--compose/config/config_schema_v2.2.json1
-rw-r--r--compose/config/config_schema_v2.3.json1
-rw-r--r--compose/config/config_schema_v3.4-beta.json1
-rw-r--r--compose/config/validation.py10
-rw-r--r--tests/unit/config/config_test.py14
7 files changed, 28 insertions, 1 deletions
diff --git a/compose/config/config_schema_v2.0.json b/compose/config/config_schema_v2.0.json
index 14bafab4..2ad62ac5 100644
--- a/compose/config/config_schema_v2.0.json
+++ b/compose/config/config_schema_v2.0.json
@@ -41,6 +41,7 @@
}
},
+ "patternProperties": {"^x-": {}},
"additionalProperties": false,
"definitions": {
diff --git a/compose/config/config_schema_v2.1.json b/compose/config/config_schema_v2.1.json
index 8a5e1283..24e6ba02 100644
--- a/compose/config/config_schema_v2.1.json
+++ b/compose/config/config_schema_v2.1.json
@@ -41,6 +41,7 @@
}
},
+ "patternProperties": {"^x-": {}},
"additionalProperties": false,
"definitions": {
diff --git a/compose/config/config_schema_v2.2.json b/compose/config/config_schema_v2.2.json
index 58ba409f..86fc5df9 100644
--- a/compose/config/config_schema_v2.2.json
+++ b/compose/config/config_schema_v2.2.json
@@ -41,6 +41,7 @@
}
},
+ "patternProperties": {"^x-": {}},
"additionalProperties": false,
"definitions": {
diff --git a/compose/config/config_schema_v2.3.json b/compose/config/config_schema_v2.3.json
index 7a9bdfdf..a790bb40 100644
--- a/compose/config/config_schema_v2.3.json
+++ b/compose/config/config_schema_v2.3.json
@@ -41,6 +41,7 @@
}
},
+ "patternProperties": {"^x-": {}},
"additionalProperties": false,
"definitions": {
diff --git a/compose/config/config_schema_v3.4-beta.json b/compose/config/config_schema_v3.4-beta.json
index 190c05f2..cba06320 100644
--- a/compose/config/config_schema_v3.4-beta.json
+++ b/compose/config/config_schema_v3.4-beta.json
@@ -64,6 +64,7 @@
}
},
+ "patternProperties": {"^x-": {}},
"additionalProperties": false,
"definitions": {
diff --git a/compose/config/validation.py b/compose/config/validation.py
index 0b7961e5..c6722a14 100644
--- a/compose/config/validation.py
+++ b/compose/config/validation.py
@@ -239,6 +239,16 @@ def handle_error_for_schema_with_id(error, path):
invalid_config_key = parse_key_from_error_msg(error)
return get_unsupported_config_msg(path, invalid_config_key)
+ if schema_id.startswith('config_schema_v'):
+ invalid_config_key = parse_key_from_error_msg(error)
+ return ('Invalid top-level property "{key}". Valid top-level '
+ 'sections for this Compose file are: {properties}, and '
+ 'extensions starting with "x-".\n\n{explanation}').format(
+ key=invalid_config_key,
+ properties=', '.join(error.schema['properties'].keys()),
+ explanation=VERSION_EXPLANATION
+ )
+
if not error.path:
return '{}\n\n{}'.format(error.message, VERSION_EXPLANATION)
diff --git a/tests/unit/config/config_test.py b/tests/unit/config/config_test.py
index 64429015..14dd0117 100644
--- a/tests/unit/config/config_test.py
+++ b/tests/unit/config/config_test.py
@@ -251,7 +251,7 @@ class ConfigTest(unittest.TestCase):
)
)
- assert 'Additional properties are not allowed' in excinfo.exconly()
+ assert 'Invalid top-level property "web"' in excinfo.exconly()
assert VERSION_EXPLANATION in excinfo.exconly()
def test_named_volume_config_empty(self):
@@ -773,6 +773,18 @@ class ConfigTest(unittest.TestCase):
assert services[1]['name'] == 'db'
assert services[2]['name'] == 'web'
+ def test_load_with_extensions(self):
+ config_details = build_config_details({
+ 'version': '2.3',
+ 'x-data': {
+ 'lambda': 3,
+ 'excess': [True, {}]
+ }
+ })
+
+ config_data = config.load(config_details)
+ assert config_data.services == []
+
def test_config_build_configuration(self):
service = config.load(
build_config_details(