Add support for extension fields in v2.x and v3.4

Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
Joffrey F 2017-08-25 18:09:06 -07:00 committed by Joffrey F
parent 42aa1c3447
commit 8c6f2217c4
7 changed files with 28 additions and 1 deletions

View File

@ -41,6 +41,7 @@
}
},
"patternProperties": {"^x-": {}},
"additionalProperties": false,
"definitions": {

View File

@ -41,6 +41,7 @@
}
},
"patternProperties": {"^x-": {}},
"additionalProperties": false,
"definitions": {

View File

@ -41,6 +41,7 @@
}
},
"patternProperties": {"^x-": {}},
"additionalProperties": false,
"definitions": {

View File

@ -41,6 +41,7 @@
}
},
"patternProperties": {"^x-": {}},
"additionalProperties": false,
"definitions": {

View File

@ -64,6 +64,7 @@
}
},
"patternProperties": {"^x-": {}},
"additionalProperties": false,
"definitions": {

View File

@ -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)

View File

@ -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(