version=schema.version,
schema=schema))
source = """
-class {name}(Type):
+class {name}Facade(Type):
name = '{name}'
version = {version}
schema = {schema}
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 = {}
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):
global classes
schemas = json.loads(Path(options.schema).read_text("utf-8"))
capture = codegen.CodeWriter()
- capture.write("""
-from juju.client.facade import Type, ReturnMapping
- """)
+ 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
+
+ """))
schemas = [Schema(s) for s in schemas]
for schema in schemas: