Skip to content

Add nullable support to Python client #1073

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

Merged
merged 2 commits into from
Sep 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

- [ ] Read the [contribution guidelines](https://github.com/openapitools/openapi-generator/blob/master/CONTRIBUTING.md).
- [ ] Ran the shell script under `./bin/` to update Petstore sample so that CIs can verify the change. (For instance, only need to run `./bin/{LANG}-petstore.sh` and `./bin/security/{LANG}-petstore.sh` if updating the {LANG} (e.g. php, ruby, python, etc) code generator or {LANG} client's mustache templates). Windows batch files can be found in `.\bin\windows\`.
- [ ] Filed the PR against the [correct branch](https://github.com/OpenAPITools/openapi-generator/wiki/Git-Branches): `master`, `3.3.x`, `4.0.x`. Default: `master`.
- [ ] Filed the PR against the [correct branch](https://github.com/OpenAPITools/openapi-generator/wiki/Git-Branches): `master` (3.3.x), `4.0.x`. Default: `master`.
- [ ] Copied the [technical committee](https://github.com/openapitools/openapi-generator/#62---openapi-generator-technical-committee) to review the pull request if your PR is targeting a particular programming language.

### Description of the PR
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,14 @@ class {{classname}}(object):
local_var_params[key] = val
del local_var_params['kwargs']
{{#allParams}}
{{^isNullable}}
{{#required}}
# verify the required parameter '{{paramName}}' is set
if ('{{paramName}}' not in local_var_params or
local_var_params['{{paramName}}'] is None):
raise ValueError("Missing the required parameter `{{paramName}}` when calling `{{operationId}}`") # noqa: E501
{{/required}}
{{/isNullable}}
{{/allParams}}

{{#allParams}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,13 @@ class {{classname}}(object):
self.{{name}} = {{name}}
{{/required}}
{{^required}}
{{#isNullable}}
self.{{name}} = {{name}}
{{/isNullable}}
{{^isNullable}}
if {{name}} is not None:
self.{{name}} = {{name}}
{{/isNullable}}
{{/required}}
{{/vars}}

Expand Down Expand Up @@ -94,10 +99,12 @@ class {{classname}}(object):
:param {{name}}: The {{name}} of this {{classname}}. # noqa: E501
:type: {{dataType}}
"""
{{^isNullable}}
{{#required}}
if {{name}} is None:
raise ValueError("Invalid value for `{{name}}`, must not be `None`") # noqa: E501
{{/required}}
{{/isNullable}}
{{#isEnum}}
{{#isContainer}}
allowed_values = [{{#allowableValues}}{{#values}}{{#items.isString}}"{{/items.isString}}{{{this}}}{{#items.isString}}"{{/items.isString}}{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}] # noqa: E501
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.2-SNAPSHOT
3.3.0-SNAPSHOT
2 changes: 1 addition & 1 deletion samples/client/petstore/python-asyncio/docs/MapTest.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Name | Type | Description | Notes
**map_map_of_string** | **dict(str, dict(str, str))** | | [optional]
**map_of_enum_string** | **dict(str, str)** | | [optional]
**direct_map** | **dict(str, bool)** | | [optional]
**indirect_map** | [**StringBooleanMap**](StringBooleanMap.md) | | [optional]
**indirect_map** | **dict(str, bool)** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MapTest(object):
'map_map_of_string': 'dict(str, dict(str, str))',
'map_of_enum_string': 'dict(str, str)',
'direct_map': 'dict(str, bool)',
'indirect_map': 'StringBooleanMap'
'indirect_map': 'dict(str, bool)'
}

attribute_map = {
Expand Down Expand Up @@ -138,7 +138,7 @@ def indirect_map(self):


:return: The indirect_map of this MapTest. # noqa: E501
:rtype: StringBooleanMap
:rtype: dict(str, bool)
"""
return self._indirect_map

Expand All @@ -148,7 +148,7 @@ def indirect_map(self, indirect_map):


:param indirect_map: The indirect_map of this MapTest. # noqa: E501
:type: StringBooleanMap
:type: dict(str, bool)
"""

self._indirect_map = indirect_map
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.2-SNAPSHOT
3.3.0-SNAPSHOT
2 changes: 1 addition & 1 deletion samples/client/petstore/python-tornado/docs/MapTest.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Name | Type | Description | Notes
**map_map_of_string** | **dict(str, dict(str, str))** | | [optional]
**map_of_enum_string** | **dict(str, str)** | | [optional]
**direct_map** | **dict(str, bool)** | | [optional]
**indirect_map** | [**StringBooleanMap**](StringBooleanMap.md) | | [optional]
**indirect_map** | **dict(str, bool)** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MapTest(object):
'map_map_of_string': 'dict(str, dict(str, str))',
'map_of_enum_string': 'dict(str, str)',
'direct_map': 'dict(str, bool)',
'indirect_map': 'StringBooleanMap'
'indirect_map': 'dict(str, bool)'
}

attribute_map = {
Expand Down Expand Up @@ -138,7 +138,7 @@ def indirect_map(self):


:return: The indirect_map of this MapTest. # noqa: E501
:rtype: StringBooleanMap
:rtype: dict(str, bool)
"""
return self._indirect_map

Expand All @@ -148,7 +148,7 @@ def indirect_map(self, indirect_map):


:param indirect_map: The indirect_map of this MapTest. # noqa: E501
:type: StringBooleanMap
:type: dict(str, bool)
"""

self._indirect_map = indirect_map
Expand Down
2 changes: 1 addition & 1 deletion samples/client/petstore/python/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.2.2-SNAPSHOT
3.3.0-SNAPSHOT
2 changes: 1 addition & 1 deletion samples/client/petstore/python/docs/MapTest.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Name | Type | Description | Notes
**map_map_of_string** | **dict(str, dict(str, str))** | | [optional]
**map_of_enum_string** | **dict(str, str)** | | [optional]
**direct_map** | **dict(str, bool)** | | [optional]
**indirect_map** | [**StringBooleanMap**](StringBooleanMap.md) | | [optional]
**indirect_map** | **dict(str, bool)** | | [optional]

[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class MapTest(object):
'map_map_of_string': 'dict(str, dict(str, str))',
'map_of_enum_string': 'dict(str, str)',
'direct_map': 'dict(str, bool)',
'indirect_map': 'StringBooleanMap'
'indirect_map': 'dict(str, bool)'
}

attribute_map = {
Expand Down Expand Up @@ -138,7 +138,7 @@ def indirect_map(self):


:return: The indirect_map of this MapTest. # noqa: E501
:rtype: StringBooleanMap
:rtype: dict(str, bool)
"""
return self._indirect_map

Expand All @@ -148,7 +148,7 @@ def indirect_map(self, indirect_map):


:param indirect_map: The indirect_map of this MapTest. # noqa: E501
:type: StringBooleanMap
:type: dict(str, bool)
"""

self._indirect_map = indirect_map
Expand Down