Created by: sebastien-rosset
Add support for the 'null' type, and retain existing behavior for OAS 3.0.x documents that don't use the 'null' type.
In OAS 3.1, the 'null' type is supported, and some existing 3.0.x documents use the 'null' type, even though it's not actually supported by the OAS 3.0 spec.
As an example, a schema may be defined as:
type: 'null'
This is useful in the following scenario when a property may be null or some referenced complex type:
Order:
type: object
properties:
billTo:
oneOf:
- type: 'null'
- $ref: "#/definitions/Address"
In 3.0.x, the above snippet could be written differently by using "nullable: true", but the nullable attribute in being deprecated in OAS 3.1. See #5180 for issues related to the 'nullable' attribute.
When a OAS document does not explicitly specify a 'null' value, the generated code should not accept a null value. In practice, some language generators such as go-experimental are lenient and allow null values. Other generators such as the python-experimental module perform a strict validation of the payload (e.g. server response). If the response is null but the OAS schema does not allow null values, the client raises an exception such as the one below:
Exception when calling API: Invalid type for variable 'parent'.
Required value type is MoOptionalBaseMo and passed type was NoneType at
['received_data']['results'][0]['parent']
PR checklist
-
Read the contribution guidelines. -
If contributing template-only or documentation-only changes which will change sample output, build the project before. -
Run the shell script(s) under ./bin/
(or Windows batch scripts under.\bin\windows
) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run./bin/{LANG}-petstore.sh
,./bin/openapi3/{LANG}-petstore.sh
if updating the code or mustache templates for a language ({LANG}
) (e.g. php, ruby, python, etc). -
File the PR against the correct branch: master
,4.3.x
,5.0.x
. Default:master
. -
Copy the technical committee to review the pull request if your PR is targeting a particular programming language.