Skip to content

Commit 457b296

Browse files
committed
Improve handling of optional properties in model to_dict
Also bumped to 0.1.2
1 parent fc37c39 commit 457b296

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## 0.1.2 - 2020-03-16
8+
- Improve handling of optional properties in generated `to_dict` function for models
9+
710
## 0.1.1 - 2020-03-06
811
- Fix mypy issue in generated models `from_dict` with datetime or reference properties
912
- Generated clients now raise an `ApiResponseError` if they receive a response that was not declared

openapi_python_client/templates/model.pyi

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ class {{ schema.reference.class_name }}:
1818

1919
def to_dict(self) -> Dict:
2020
return {
21-
{% for property in schema.required_properties + schema.optional_properties %}
22-
"{{ property.name }}": self.{{ property.transform() }} if self.{{ property.name }} else None,
21+
{% for property in schema.required_properties %}
22+
"{{ property.name }}": self.{{ property.transform() }},
23+
{% endfor %}
24+
{% for property in schema.optional_properties %}
25+
"{{ property.name }}": self.{{ property.transform() }} if self.{{ property.name }} is not None else None,
2326
{% endfor %}
2427
}
2528

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "openapi-python-client"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
description = "Generate modern Python clients from OpenAPI"
55

66
authors = [

0 commit comments

Comments
 (0)