Hook up Unit.run() to api
[osm/N2VC.git] / juju / client / facade.py
index 048e5c5..41166c0 100644 (file)
@@ -395,7 +395,7 @@ def buildFacade(schema):
                                           version=schema.version,
                                           schema=schema))
     source = """
-class {name}(Type):
+class {name}Facade(Type):
     name = '{name}'
     version = {version}
     schema = {schema}
@@ -428,7 +428,11 @@ class Type:
         for k, v in (data or {}).items():
             d[cls._toPy.get(k, k)] = v
 
-        return cls(**d)
+        try:
+            return cls(**d)
+        except TypeError:
+            print(cls)
+            raise
 
     def serialize(self):
         d = {}
@@ -526,7 +530,10 @@ class Schema(dict):
                 add((name, self.buildArray(pprop, d + 1)))
             else:
                 add((name, Mapping[str, SCHEMA_TO_PYTHON[ppkind]]))
-            #print("{}{}".format(d * "   ", struct))
+
+        if not struct and node.get('additionalProperties', False):
+            add((name, Mapping[str, SCHEMA_TO_PYTHON['object']]))
+
         return struct
 
     def buildArray(self, obj, d=0):
@@ -558,12 +565,13 @@ def generate_facacdes(options):
     global classes
     schemas = json.loads(Path(options.schema).read_text("utf-8"))
     capture = codegen.CodeWriter()
-    capture.write("""
-# DO NOT CHANGE THIS FILE! This file is auto-generated by facade.py.
-# Changes will be overwritten/lost when the file is regenerated.
+    capture.write(textwrap.dedent("""\
+        # DO NOT CHANGE THIS FILE! This file is auto-generated by facade.py.
+        # Changes will be overwritten/lost when the file is regenerated.
+
+        from juju.client.facade import Type, ReturnMapping
 
-from juju.client.facade import Type, ReturnMapping
-                  """)
+    """))
     schemas = [Schema(s) for s in schemas]
 
     for schema in schemas: