From 1dc3d826647236215e6dd75425d921e5f70b303d Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Fri, 29 May 2015 15:58:33 +0100 Subject: [PATCH] Load swagger APIs as templating units. Check sections return strings. --- templating/batesian/sections.py | 4 ++++ templating/matrix_templates/sections.py | 1 + templating/matrix_templates/units.py | 13 +++++++++++++ 3 files changed, 18 insertions(+) diff --git a/templating/batesian/sections.py b/templating/batesian/sections.py index 9b1da5b5..aa97662c 100644 --- a/templating/batesian/sections.py +++ b/templating/batesian/sections.py @@ -26,6 +26,10 @@ class Sections(object): continue section_key = func_name[len("render_"):] section = func() + if not isinstance(section, basestring): + raise Exception( + "Section function '%s' didn't return a string!" % func_name + ) section_dict[section_key] = section self.log("Generated section '%s' : %s" % ( section_key, section[:60].replace("\n","") diff --git a/templating/matrix_templates/sections.py b/templating/matrix_templates/sections.py index 0b94e100..2d35b8ae 100644 --- a/templating/matrix_templates/sections.py +++ b/templating/matrix_templates/sections.py @@ -2,6 +2,7 @@ from batesian import AccessKeyStore from batesian.sections import Sections import inspect +import json import os diff --git a/templating/matrix_templates/units.py b/templating/matrix_templates/units.py index bf0fefa6..485a5f75 100644 --- a/templating/matrix_templates/units.py +++ b/templating/matrix_templates/units.py @@ -4,10 +4,23 @@ import inspect import json import os import subprocess +import yaml class MatrixUnits(Units): + def load_swagger_apis(self): + path = "../api/client-server/v1" + apis = {} + for filename in os.listdir(path): + if not filename.endswith(".yaml"): + continue + self.log("Reading swagger API: %s" % filename) + with open(os.path.join(path, filename), "r") as f: + # strip .yaml + apis[filename[:-5]] = yaml.load(f.read()) + return apis + def load_common_event_fields(self): path = "../event-schemas/schema/v1/core" event_types = {}