Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Python] Generated code does not respect nullable values #8710

Closed
fridex opened this issue Sep 18, 2018 · 7 comments · May be fixed by #10906
Closed

[Python] Generated code does not respect nullable values #8710

fridex opened this issue Sep 18, 2018 · 7 comments · May be fixed by #10906
Assignees

Comments

@fridex
Copy link

fridex commented Sep 18, 2018

Description

There is always generated following code which prevents from None (null) values:

        if requirements_lock is None:
            raise ValueError("Invalid value for `<attr_name>`, must not be `None`")  # noqa: E501

Unfortunately this check is generated even if the swagger definition explicitly says the given model attribute is nullable (by providing nullable: true).

Swagger-codegen version

The latest master to this date - master SHA 554d443.

Swagger declaration file content or url
Command line used for generation
java -jar swagger-codegen/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i "${SWAGGER_YAML}" -l python
Steps to reproduce

Use any swagger definition and set nullable to true to any model attribute.

Related issues/PRs

None found.

Suggest a fix/enhancement

{{#required}}
if {{name}} is None:
raise ValueError("Invalid value for `{{name}}`, must not be `None`") # noqa: E501
{{/required}}

{{#required}}
if {{name}} is None:
raise ValueError("Invalid value for `{{name}}`, must not be `None`") # noqa: E501
{{/required}}

@heckad
Copy link

heckad commented Feb 1, 2019

It is no fixed. When property with enum and nullable:true None doesn`t add in allowed_values.

@imissyouso
Copy link

I have the same issue using v2.4.8

@esseti
Copy link

esseti commented Jan 9, 2020

I'm facing the same problem apparently. is this solved?

@anichari
Copy link

anichari commented Apr 17, 2020

+1 any update on if there is going to be a code change so that the None check is added only if nullable is not True?
In particular, if the given property is a required property for the model , and nullable flag is True, then the codegen should not raise on null check

@HugoMario HugoMario self-assigned this Jul 17, 2020
@HugoMario
Copy link
Contributor

hey guys, sorry for delay on. this issue.

According to links pointing to code in templates, the check it's only added when the property is required. So, it does not make sense to have a nullable required property.

What do you guys think?

https://stackoverflow.com/questions/45575493/what-does-required-in-openapi-really-mean

@dRacz3
Copy link

dRacz3 commented Dec 23, 2020

@HugoMario
Having the property listed in required would mean, that in the response the property must be there, but it does not specify it's value, which can be also null if nullable = True is set in the specification, therefore it is a bug imo.

Also, this issue seems to describe the same problem: #10535

(I have also experienced this issue with some project, and will not use the swagger codegen to generate my python client due to this problem). I have used the docker images for testing it. Checked back till a version 3.0.15, does not seem to work with any version :(

@aarighi
Copy link

aarighi commented Aug 9, 2021

Hi, still have the same problem. Is there any progress?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants