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 to required. Then, I marked the fields that can be null as nullable: true.
However, in the python model template, required results in:
|
{{#required}} |
|
if {{name}} is None: |
|
raise ValueError("Invalid value for `{{name}}`, must not be `None`") # noqa: E501 |
|
{{/required}} |
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
components:
schemas:
MySomethingOrOther:
type: object
required:
- id
- required_nullable_option
properties:
id:
type: integer
example: 96
required_nullable_option:
type: string
nullable: true
example: "something"
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
|
{{#required}} |
|
if {{name}} is None: |
|
raise ValueError("Invalid value for `{{name}}`, must not be `None`") # noqa: E501 |
|
{{/required}} |
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.
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
requestBodyparameters, and adding all of them torequired. Then, I marked the fields that can be null asnullable: true.However, in the python model template,
requiredresults 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.