add jsonschema validation to the start of the template rendering

Change-Id: I289b4497ceffec896bbcda42d89c15fb88aba1c4
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann 2017-06-21 15:34:01 -04:00
parent 2cd097916d
commit 8715ead60f
3 changed files with 36 additions and 1 deletions

View File

@ -18,6 +18,7 @@ reno>=1.8.0,!=2.3.1 # Apache-2.0
sphinxmark>=0.1.14 # Apache-2.0
lxml>=2.3,!=3.7.0 # BSD
PyYAML>=3.10.0 # MIT
jsonschema>=2.6.0
# For translations
# Babel 2.4.0 is broken, fixed in 2.4.1

View File

@ -19,6 +19,7 @@ import sys
from bs4 import BeautifulSoup
import jinja2
import jsonschema
import yaml
@ -70,7 +71,19 @@ def main():
if os.path.exists(project_data_filename):
with open(project_data_filename, 'r') as f:
project_data = yaml.safe_load(f.read())
project_schema_filename = os.path.join(
args.source_directory,
'schema.yaml',
)
with open(project_schema_filename, 'r') as f:
project_schema = yaml.safe_load(f.read())
validator = jsonschema.Draft4Validator(project_schema)
fail = False
for error in validator.iter_errors(project_data):
logger.error(str(error))
fail = True
if fail:
raise ValueError('invalid input in %s' % project_data_filename)
try:
loader = jinja2.FileSystemLoader(args.source_directory)
environment = jinja2.Environment(loader=loader)

21
www/schema.yaml Normal file
View File

@ -0,0 +1,21 @@
---
additionalProperties: false
type: array
items:
type: object
required:
- name
- service
- type
properties:
name:
type: string
service:
type: string
type:
type: string
enum: ["service", "client", "library", "other"]
description:
type: string
has_install_guide:
type: boolean