Skip to content

[PYTHON] Generated code disregards nullable flagΒ #10535

@noamgat

Description

@noamgat
Description

I generated a data structure that has a nullable property, yet the python code that is generated does not see it.

Swagger-codegen version

https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/2.4.16/swagger-codegen-cli-2.4.16.jar

Swagger declaration file content or url
"ProjectProfile": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "number"
                },
                "result": {
                    "type": "object",
                    "description": "An object from the JSON field in the database",
                    "nullable": true,
                    "default": {}
                }
            },
            "required": ["id", "result"]
        },
Command line used for generation

java -jar swagger-codegen-cli.jar generate -i http://localhost:3001/api-docs-json -l python -o swapp_system_client_package -DpackageName=swapp_system_client

Steps to reproduce

run codegen with json snippet, this is how the python will look for result setter:

@result.setter
    def result(self, result):
        """Sets the result of this ProjectProfile.

        An object from the JSON field in the database  # noqa: E501

        :param result: The result of this ProjectProfile.  # noqa: E501
        :type: object
        """
        if result is None:
            raise ValueError("Invalid value for `result`, must not be `None`")  # noqa: E501

        self._result = result
Related issues/PRs
Suggest a fix/enhancement

It seems like nullable flag does not affect the setter code generation in python.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions