-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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] required AND nullable #579
Comments
@cognifloyd yes, may I know if you've time to contribute the enhancement? I can show you some good starting points. |
I looked to see if nullable was set injected into the templates, but it's not. A couple of the templates use |
I found the inclination and so went digging through the Java even though I'm a rookie with Java. I started with swagger-codegen (because I'm using it via swaggerhub right now and I'm getting irritated with OAS 2.0) and then came to do the same here and discovered that the Java side is done.
And go figure. I didn't know what I was doing in swagger-codegen, so I updated (squash + force push) my PRs there based on your excellent work here.
Now, I hope I can find some more time to actually work on the python side. |
@cognifloyd I've submitted #1073 before. Is that what you're looking for? (sorry that I forgot to update you about this enhancement before) |
Wow. yeah. That's great! 🎉 Thank you @wing328 for doing that. Now to play with and use it. |
@cognifloyd you're welcome. Please give it a try and let us know if you've any feedback. |
it seems to be again a problem since release 3.3.2 |
@sanderegg can you please elaborate on the issue with a spec to reproduce the problem and the actual vs expected output? |
@wing328 sorry yes, actually the exact same case described in here.
The generated code for this part now creates: if data is None:
raise ValueError("Invalid value for 'data', must not be 'None'") And it is not the case with version 3.3.1 |
@cognifloyd thanks for sharing the spec. Are you using OpenAPI spec v2 or v3? Only v3 officially supports |
I also did a test locally and it's working fine. |
@wing328 using spec v3 |
@cognifloyd I was not able to repeat the issue with OAS3 spec using the latest master. The nullable support was introduced to v3.3.0 via #1073. Can you please try the latest master instead? You can find the links to the SNAPSHOT version in the project's README. |
@wing328 I think you meant @sanderegg :) |
I'm using the docker images, is there one for master as well? like latest? it seems to be recent. |
well using the latest docker (which is an hour old at this time of writing) I get the same issue. |
@cognifloyd sorry :( @sanderegg can you please share the full spec with me so that I can repeat the issue locally? You can find my email address in my Github profile page. |
yes will do in the evening... going home at the moment... |
Ok I think I found the issue. It seems the problem arises when the property is nullable and a ref (see schema that reproduces the issue below). I confirm that the problem with nullable of type string works fine. The problem arises when the property is a ref and nullable.
|
so replacing the above specs, by
works! Thanks for your time, I think it's all good! probably made my api better;) |
Description
I'm modeling an existing api in an OpenAPI 3.0 spec.
A key thing across most of this particular API (like it or not) is that all fields must be present (they are all required), but most of the time the fields are nullable. Some APIs include the fields and never use them (ie they are always set to null), but try to send a request without the field and it fails. (A replacement API is in the works, but until then, legacy prevails...)
So, I tried to model this by listing the
requestBody
parameters, and adding all of them torequired
. Then, I marked the fields that can be null asnullable: true
.However, in the python model template,
required
results in:openapi-generator/modules/openapi-generator/src/main/resources/python/model.mustache
Lines 97 to 100 in 7184f1e
Could this be updated to support nullable? So that it raises the ValueError on None only if required and NOT nullable?
openapi-generator version
master
OpenAPI declaration file content or url
Command line used for generation
python is the target
Steps to reproduce
Mark something as both required and nullable, and then pass None as the value.
Suggest a fix/enhancement
check for required and not nullable
openapi-generator/modules/openapi-generator/src/main/resources/python/model.mustache
Lines 97 to 100 in 7184f1e
I'm not familiar with what sets the vars like "required" in the template, so I'm not sure where to get the nullable option to modify this.
The text was updated successfully, but these errors were encountered: