Skip to content

Commit 26899ee

Browse files
baptiste-le-mBaptiste LE MORLEC
andauthored
Adding model type hints for Python Flask (#16382)
Co-authored-by: Baptiste LE MORLEC <baptiste.lemorlec@stryker.com>
1 parent 9cda7b0 commit 26899ee

7 files changed

Lines changed: 56 additions & 56 deletions

File tree

modules/openapi-generator/src/main/resources/python-flask/model.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class {{classname}}(Model):
7171

7272
{{/-first}}
7373
@property
74-
def {{name}}(self):
74+
def {{name}}(self) -> {{dataType}}:
7575
"""Gets the {{name}} of this {{classname}}.
7676

7777
{{#description}}
@@ -84,7 +84,7 @@ class {{classname}}(Model):
8484
return self._{{name}}
8585

8686
@{{name}}.setter
87-
def {{name}}(self, {{name}}):
87+
def {{name}}(self, {{name}}: {{dataType}}):
8888
"""Sets the {{name}} of this {{classname}}.
8989

9090
{{#description}}

samples/server/petstore/python-flask/openapi_server/models/api_response.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def from_dict(cls, dikt) -> 'ApiResponse':
5050
return util.deserialize_model(dikt, cls)
5151

5252
@property
53-
def code(self):
53+
def code(self) -> int:
5454
"""Gets the code of this ApiResponse.
5555
5656
@@ -60,7 +60,7 @@ def code(self):
6060
return self._code
6161

6262
@code.setter
63-
def code(self, code):
63+
def code(self, code: int):
6464
"""Sets the code of this ApiResponse.
6565
6666
@@ -71,7 +71,7 @@ def code(self, code):
7171
self._code = code
7272

7373
@property
74-
def type(self):
74+
def type(self) -> str:
7575
"""Gets the type of this ApiResponse.
7676
7777
@@ -81,7 +81,7 @@ def type(self):
8181
return self._type
8282

8383
@type.setter
84-
def type(self, type):
84+
def type(self, type: str):
8585
"""Sets the type of this ApiResponse.
8686
8787
@@ -92,7 +92,7 @@ def type(self, type):
9292
self._type = type
9393

9494
@property
95-
def message(self):
95+
def message(self) -> str:
9696
"""Gets the message of this ApiResponse.
9797
9898
@@ -102,7 +102,7 @@ def message(self):
102102
return self._message
103103

104104
@message.setter
105-
def message(self, message):
105+
def message(self, message: str):
106106
"""Sets the message of this ApiResponse.
107107
108108

samples/server/petstore/python-flask/openapi_server/models/category.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def from_dict(cls, dikt) -> 'Category':
4545
return util.deserialize_model(dikt, cls)
4646

4747
@property
48-
def id(self):
48+
def id(self) -> int:
4949
"""Gets the id of this Category.
5050
5151
@@ -55,7 +55,7 @@ def id(self):
5555
return self._id
5656

5757
@id.setter
58-
def id(self, id):
58+
def id(self, id: int):
5959
"""Sets the id of this Category.
6060
6161
@@ -66,7 +66,7 @@ def id(self, id):
6666
self._id = id
6767

6868
@property
69-
def name(self):
69+
def name(self) -> str:
7070
"""Gets the name of this Category.
7171
7272
@@ -76,7 +76,7 @@ def name(self):
7676
return self._name
7777

7878
@name.setter
79-
def name(self, name):
79+
def name(self, name: str):
8080
"""Sets the name of this Category.
8181
8282

samples/server/petstore/python-flask/openapi_server/models/order.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def from_dict(cls, dikt) -> 'Order':
6565
return util.deserialize_model(dikt, cls)
6666

6767
@property
68-
def id(self):
68+
def id(self) -> int:
6969
"""Gets the id of this Order.
7070
7171
@@ -75,7 +75,7 @@ def id(self):
7575
return self._id
7676

7777
@id.setter
78-
def id(self, id):
78+
def id(self, id: int):
7979
"""Sets the id of this Order.
8080
8181
@@ -86,7 +86,7 @@ def id(self, id):
8686
self._id = id
8787

8888
@property
89-
def pet_id(self):
89+
def pet_id(self) -> int:
9090
"""Gets the pet_id of this Order.
9191
9292
@@ -96,7 +96,7 @@ def pet_id(self):
9696
return self._pet_id
9797

9898
@pet_id.setter
99-
def pet_id(self, pet_id):
99+
def pet_id(self, pet_id: int):
100100
"""Sets the pet_id of this Order.
101101
102102
@@ -107,7 +107,7 @@ def pet_id(self, pet_id):
107107
self._pet_id = pet_id
108108

109109
@property
110-
def quantity(self):
110+
def quantity(self) -> int:
111111
"""Gets the quantity of this Order.
112112
113113
@@ -117,7 +117,7 @@ def quantity(self):
117117
return self._quantity
118118

119119
@quantity.setter
120-
def quantity(self, quantity):
120+
def quantity(self, quantity: int):
121121
"""Sets the quantity of this Order.
122122
123123
@@ -128,7 +128,7 @@ def quantity(self, quantity):
128128
self._quantity = quantity
129129

130130
@property
131-
def ship_date(self):
131+
def ship_date(self) -> datetime:
132132
"""Gets the ship_date of this Order.
133133
134134
@@ -138,7 +138,7 @@ def ship_date(self):
138138
return self._ship_date
139139

140140
@ship_date.setter
141-
def ship_date(self, ship_date):
141+
def ship_date(self, ship_date: datetime):
142142
"""Sets the ship_date of this Order.
143143
144144
@@ -149,7 +149,7 @@ def ship_date(self, ship_date):
149149
self._ship_date = ship_date
150150

151151
@property
152-
def status(self):
152+
def status(self) -> str:
153153
"""Gets the status of this Order.
154154
155155
Order Status # noqa: E501
@@ -160,7 +160,7 @@ def status(self):
160160
return self._status
161161

162162
@status.setter
163-
def status(self, status):
163+
def status(self, status: str):
164164
"""Sets the status of this Order.
165165
166166
Order Status # noqa: E501
@@ -178,7 +178,7 @@ def status(self, status):
178178
self._status = status
179179

180180
@property
181-
def complete(self):
181+
def complete(self) -> bool:
182182
"""Gets the complete of this Order.
183183
184184
@@ -188,7 +188,7 @@ def complete(self):
188188
return self._complete
189189

190190
@complete.setter
191-
def complete(self, complete):
191+
def complete(self, complete: bool):
192192
"""Sets the complete of this Order.
193193
194194

samples/server/petstore/python-flask/openapi_server/models/pet.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def from_dict(cls, dikt) -> 'Pet':
6969
return util.deserialize_model(dikt, cls)
7070

7171
@property
72-
def id(self):
72+
def id(self) -> int:
7373
"""Gets the id of this Pet.
7474
7575
@@ -79,7 +79,7 @@ def id(self):
7979
return self._id
8080

8181
@id.setter
82-
def id(self, id):
82+
def id(self, id: int):
8383
"""Sets the id of this Pet.
8484
8585
@@ -90,7 +90,7 @@ def id(self, id):
9090
self._id = id
9191

9292
@property
93-
def category(self):
93+
def category(self) -> Category:
9494
"""Gets the category of this Pet.
9595
9696
@@ -100,7 +100,7 @@ def category(self):
100100
return self._category
101101

102102
@category.setter
103-
def category(self, category):
103+
def category(self, category: Category):
104104
"""Sets the category of this Pet.
105105
106106
@@ -111,7 +111,7 @@ def category(self, category):
111111
self._category = category
112112

113113
@property
114-
def name(self):
114+
def name(self) -> str:
115115
"""Gets the name of this Pet.
116116
117117
@@ -121,7 +121,7 @@ def name(self):
121121
return self._name
122122

123123
@name.setter
124-
def name(self, name):
124+
def name(self, name: str):
125125
"""Sets the name of this Pet.
126126
127127
@@ -134,7 +134,7 @@ def name(self, name):
134134
self._name = name
135135

136136
@property
137-
def photo_urls(self):
137+
def photo_urls(self) -> List[str]:
138138
"""Gets the photo_urls of this Pet.
139139
140140
@@ -144,7 +144,7 @@ def photo_urls(self):
144144
return self._photo_urls
145145

146146
@photo_urls.setter
147-
def photo_urls(self, photo_urls):
147+
def photo_urls(self, photo_urls: List[str]):
148148
"""Sets the photo_urls of this Pet.
149149
150150
@@ -157,7 +157,7 @@ def photo_urls(self, photo_urls):
157157
self._photo_urls = photo_urls
158158

159159
@property
160-
def tags(self):
160+
def tags(self) -> List[Tag]:
161161
"""Gets the tags of this Pet.
162162
163163
@@ -167,7 +167,7 @@ def tags(self):
167167
return self._tags
168168

169169
@tags.setter
170-
def tags(self, tags):
170+
def tags(self, tags: List[Tag]):
171171
"""Sets the tags of this Pet.
172172
173173
@@ -178,7 +178,7 @@ def tags(self, tags):
178178
self._tags = tags
179179

180180
@property
181-
def status(self):
181+
def status(self) -> str:
182182
"""Gets the status of this Pet.
183183
184184
pet status in the store # noqa: E501
@@ -189,7 +189,7 @@ def status(self):
189189
return self._status
190190

191191
@status.setter
192-
def status(self, status):
192+
def status(self, status: str):
193193
"""Sets the status of this Pet.
194194
195195
pet status in the store # noqa: E501

samples/server/petstore/python-flask/openapi_server/models/tag.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def from_dict(cls, dikt) -> 'Tag':
4545
return util.deserialize_model(dikt, cls)
4646

4747
@property
48-
def id(self):
48+
def id(self) -> int:
4949
"""Gets the id of this Tag.
5050
5151
@@ -55,7 +55,7 @@ def id(self):
5555
return self._id
5656

5757
@id.setter
58-
def id(self, id):
58+
def id(self, id: int):
5959
"""Sets the id of this Tag.
6060
6161
@@ -66,7 +66,7 @@ def id(self, id):
6666
self._id = id
6767

6868
@property
69-
def name(self):
69+
def name(self) -> str:
7070
"""Gets the name of this Tag.
7171
7272
@@ -76,7 +76,7 @@ def name(self):
7676
return self._name
7777

7878
@name.setter
79-
def name(self, name):
79+
def name(self, name: str):
8080
"""Sets the name of this Tag.
8181
8282

0 commit comments

Comments
 (0)