json-schema-codegen
json-schema-codegen copied to clipboard
Python template fails when using kwargs only
Template is here
def __init__(self, data=None, **kwargs):
"""Initialization for the {{Name}} object.
It can be initialized with an object, or by passing each
object property as a keyword argument.
"""
new_data = {}
{%-for propName, propSchema in schema.properties.items()%}
try:
prop = data["{{propName}}"] if ("{{propName}}" in data) else kwargs["{{propName}}"]
The last line should read:
prop = data["{{propName}}"] if (data is not None and "{{propName}}" in data) else kwargs["{{propName}}"]
Otherwise when data is None, it will fail every time.