json-schema-codegen icon indicating copy to clipboard operation
json-schema-codegen copied to clipboard

Python template fails when using kwargs only

Open gadostal-swordfish opened this issue 5 years ago • 0 comments

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.

gadostal-swordfish avatar Jan 11 '21 04:01 gadostal-swordfish