Add ids to config schemas

Also enforce a max complexity for functions and add some new tests for config.

Signed-off-by: Daniel Nephin <dnephin@docker.com>
This commit is contained in:
Daniel Nephin 2015-11-12 12:40:36 -05:00
commit f7d8087694
5 changed files with 30 additions and 18 deletions

View file

@ -2,15 +2,18 @@
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"id": "fields_schema.json",
"patternProperties": {
"^[a-zA-Z0-9._-]+$": {
"$ref": "#/definitions/service"
}
},
"additionalProperties": false,
"definitions": {
"service": {
"id": "#/definitions/service",
"type": "object",
"properties": {
@ -167,6 +170,5 @@
]
}
},
"additionalProperties": false
}
}

View file

@ -1,15 +1,17 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "service_schema.json",
"type": "object",
"allOf": [
{"$ref": "fields_schema.json#/definitions/service"},
{"$ref": "#/definitions/service_constraints"}
{"$ref": "#/definitions/constraints"}
],
"definitions": {
"service_constraints": {
"constraints": {
"id": "#/definitions/constraints",
"anyOf": [
{
"required": ["build"],
@ -21,13 +23,8 @@
{"required": ["build"]},
{"required": ["dockerfile"]}
]}
},
{
"required": ["extends"],
"not": {"required": ["build", "image"]}
}
]
}
}
}

View file

@ -307,7 +307,10 @@ def _validate_against_schema(config, schema_filename, format_checker=[], service
schema = json.load(schema_fh)
resolver = RefResolver(resolver_full_path, schema)
validation_output = Draft4Validator(schema, resolver=resolver, format_checker=FormatChecker(format_checker))
validation_output = Draft4Validator(
schema,
resolver=resolver,
format_checker=FormatChecker(format_checker))
errors = [error for error in sorted(validation_output.iter_errors(config), key=str)]
if errors: