mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-08 03:18:53 +00:00
Add enum support for model property of python client
This commit is contained in:
parent
157b07e552
commit
f0e09ae33a
@ -51,8 +51,7 @@ class {{classname}}(object):
|
|||||||
{{/allParams}}
|
{{/allParams}}
|
||||||
:return: {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}None{{/returnType}}
|
:return: {{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}None{{/returnType}}
|
||||||
"""
|
"""
|
||||||
{{#allParams}}{{#required}}
|
{{#allParams}}{{#required}}# verify the required parameter '{{paramName}}' is set
|
||||||
# verify the required parameter '{{paramName}}' is set
|
|
||||||
if {{paramName}} is None:
|
if {{paramName}} is None:
|
||||||
raise ValueError("Missing the required parameter `{{paramName}}` when calling `{{nickname}}`")
|
raise ValueError("Missing the required parameter `{{paramName}}` when calling `{{nickname}}`")
|
||||||
{{/required}}{{/allParams}}
|
{{/required}}{{/allParams}}
|
||||||
|
@ -149,7 +149,7 @@ class ApiClient(object):
|
|||||||
# Convert model obj to dict except attributes `swagger_types`, `attribute_map`
|
# Convert model obj to dict except attributes `swagger_types`, `attribute_map`
|
||||||
# and attributes which value is not None.
|
# and attributes which value is not None.
|
||||||
# Convert attribute name to json key in model definition for request.
|
# Convert attribute name to json key in model definition for request.
|
||||||
obj_dict = {obj.attribute_map[key]: val
|
obj_dict = {obj.attribute_map[key[1:]]: val
|
||||||
for key, val in iteritems(obj.__dict__)
|
for key, val in iteritems(obj.__dict__)
|
||||||
if key != 'swagger_types' and key != 'attribute_map' and val is not None}
|
if key != 'swagger_types' and key != 'attribute_map' and val is not None}
|
||||||
return {key: self.sanitize_for_serialization(val)
|
return {key: self.sanitize_for_serialization(val)
|
||||||
|
@ -43,9 +43,21 @@ class {{classname}}(object):
|
|||||||
}
|
}
|
||||||
{{#vars}}
|
{{#vars}}
|
||||||
{{#description}}# {{description}}{{/description}}
|
{{#description}}# {{description}}{{/description}}
|
||||||
self.{{name}} = None # {{{datatype}}}
|
self._{{name}} = None # {{{datatype}}}
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
|
{{#vars}}
|
||||||
|
@property
|
||||||
|
def {{name}}(self):
|
||||||
|
return self._{{name}}
|
||||||
|
|
||||||
|
@{{name}}.setter
|
||||||
|
def {{name}}(self, {{name}}):
|
||||||
|
{{#isEnum}}allowed_values = [{{#allowableValues}}{{#values}}"{{{this}}}"{{^-last}}, {{/-last}}{{/values}}{{/allowableValues}}]
|
||||||
|
if {{name}} not in allowed_values:
|
||||||
|
raise ValueError("Invalid value for `{{name}}`, must be one of {0}".format(allowed_values))
|
||||||
|
{{/isEnum}}
|
||||||
|
self._{{name}} = {{name}}
|
||||||
|
{{/vars}}
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
properties = []
|
properties = []
|
||||||
for p in self.__dict__:
|
for p in self.__dict__:
|
||||||
|
@ -149,7 +149,7 @@ class ApiClient(object):
|
|||||||
# Convert model obj to dict except attributes `swagger_types`, `attribute_map`
|
# Convert model obj to dict except attributes `swagger_types`, `attribute_map`
|
||||||
# and attributes which value is not None.
|
# and attributes which value is not None.
|
||||||
# Convert attribute name to json key in model definition for request.
|
# Convert attribute name to json key in model definition for request.
|
||||||
obj_dict = {obj.attribute_map[key]: val
|
obj_dict = {obj.attribute_map[key[1:]]: val
|
||||||
for key, val in iteritems(obj.__dict__)
|
for key, val in iteritems(obj.__dict__)
|
||||||
if key != 'swagger_types' and key != 'attribute_map' and val is not None}
|
if key != 'swagger_types' and key != 'attribute_map' and val is not None}
|
||||||
return {key: self.sanitize_for_serialization(val)
|
return {key: self.sanitize_for_serialization(val)
|
||||||
|
@ -258,7 +258,6 @@ class PetApi(object):
|
|||||||
|
|
||||||
:return: Pet
|
:return: Pet
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# verify the required parameter 'pet_id' is set
|
# verify the required parameter 'pet_id' is set
|
||||||
if pet_id is None:
|
if pet_id is None:
|
||||||
raise ValueError("Missing the required parameter `pet_id` when calling `get_pet_by_id`")
|
raise ValueError("Missing the required parameter `pet_id` when calling `get_pet_by_id`")
|
||||||
@ -317,7 +316,6 @@ class PetApi(object):
|
|||||||
|
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# verify the required parameter 'pet_id' is set
|
# verify the required parameter 'pet_id' is set
|
||||||
if pet_id is None:
|
if pet_id is None:
|
||||||
raise ValueError("Missing the required parameter `pet_id` when calling `update_pet_with_form`")
|
raise ValueError("Missing the required parameter `pet_id` when calling `update_pet_with_form`")
|
||||||
@ -379,7 +377,6 @@ class PetApi(object):
|
|||||||
|
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# verify the required parameter 'pet_id' is set
|
# verify the required parameter 'pet_id' is set
|
||||||
if pet_id is None:
|
if pet_id is None:
|
||||||
raise ValueError("Missing the required parameter `pet_id` when calling `delete_pet`")
|
raise ValueError("Missing the required parameter `pet_id` when calling `delete_pet`")
|
||||||
@ -439,7 +436,6 @@ class PetApi(object):
|
|||||||
|
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# verify the required parameter 'pet_id' is set
|
# verify the required parameter 'pet_id' is set
|
||||||
if pet_id is None:
|
if pet_id is None:
|
||||||
raise ValueError("Missing the required parameter `pet_id` when calling `upload_file`")
|
raise ValueError("Missing the required parameter `pet_id` when calling `upload_file`")
|
||||||
|
@ -152,7 +152,6 @@ class StoreApi(object):
|
|||||||
|
|
||||||
:return: Order
|
:return: Order
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# verify the required parameter 'order_id' is set
|
# verify the required parameter 'order_id' is set
|
||||||
if order_id is None:
|
if order_id is None:
|
||||||
raise ValueError("Missing the required parameter `order_id` when calling `get_order_by_id`")
|
raise ValueError("Missing the required parameter `order_id` when calling `get_order_by_id`")
|
||||||
@ -209,7 +208,6 @@ class StoreApi(object):
|
|||||||
|
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# verify the required parameter 'order_id' is set
|
# verify the required parameter 'order_id' is set
|
||||||
if order_id is None:
|
if order_id is None:
|
||||||
raise ValueError("Missing the required parameter `order_id` when calling `delete_order`")
|
raise ValueError("Missing the required parameter `order_id` when calling `delete_order`")
|
||||||
|
@ -307,7 +307,6 @@ class UserApi(object):
|
|||||||
|
|
||||||
:return: User
|
:return: User
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# verify the required parameter 'username' is set
|
# verify the required parameter 'username' is set
|
||||||
if username is None:
|
if username is None:
|
||||||
raise ValueError("Missing the required parameter `username` when calling `get_user_by_name`")
|
raise ValueError("Missing the required parameter `username` when calling `get_user_by_name`")
|
||||||
@ -365,7 +364,6 @@ class UserApi(object):
|
|||||||
|
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# verify the required parameter 'username' is set
|
# verify the required parameter 'username' is set
|
||||||
if username is None:
|
if username is None:
|
||||||
raise ValueError("Missing the required parameter `username` when calling `update_user`")
|
raise ValueError("Missing the required parameter `username` when calling `update_user`")
|
||||||
@ -423,7 +421,6 @@ class UserApi(object):
|
|||||||
|
|
||||||
:return: None
|
:return: None
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# verify the required parameter 'username' is set
|
# verify the required parameter 'username' is set
|
||||||
if username is None:
|
if username is None:
|
||||||
raise ValueError("Missing the required parameter `username` when calling `delete_user`")
|
raise ValueError("Missing the required parameter `username` when calling `delete_user`")
|
||||||
|
@ -41,12 +41,30 @@ class Category(object):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
self.id = None # int
|
self._id = None # int
|
||||||
|
|
||||||
|
|
||||||
self.name = None # str
|
self._name = None # str
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def id(self):
|
||||||
|
return self._id
|
||||||
|
|
||||||
|
@id.setter
|
||||||
|
def id(self, id):
|
||||||
|
|
||||||
|
self._id = id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@name.setter
|
||||||
|
def name(self, name):
|
||||||
|
|
||||||
|
self._name = name
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
properties = []
|
properties = []
|
||||||
for p in self.__dict__:
|
for p in self.__dict__:
|
||||||
|
@ -49,24 +49,81 @@ class Order(object):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
self.id = None # int
|
self._id = None # int
|
||||||
|
|
||||||
|
|
||||||
self.pet_id = None # int
|
self._pet_id = None # int
|
||||||
|
|
||||||
|
|
||||||
self.quantity = None # int
|
self._quantity = None # int
|
||||||
|
|
||||||
|
|
||||||
self.ship_date = None # datetime
|
self._ship_date = None # datetime
|
||||||
|
|
||||||
# Order Status
|
# Order Status
|
||||||
self.status = None # str
|
self._status = None # str
|
||||||
|
|
||||||
|
|
||||||
self.complete = None # bool
|
self._complete = None # bool
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def id(self):
|
||||||
|
return self._id
|
||||||
|
|
||||||
|
@id.setter
|
||||||
|
def id(self, id):
|
||||||
|
|
||||||
|
self._id = id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def pet_id(self):
|
||||||
|
return self._pet_id
|
||||||
|
|
||||||
|
@pet_id.setter
|
||||||
|
def pet_id(self, pet_id):
|
||||||
|
|
||||||
|
self._pet_id = pet_id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def quantity(self):
|
||||||
|
return self._quantity
|
||||||
|
|
||||||
|
@quantity.setter
|
||||||
|
def quantity(self, quantity):
|
||||||
|
|
||||||
|
self._quantity = quantity
|
||||||
|
|
||||||
|
@property
|
||||||
|
def ship_date(self):
|
||||||
|
return self._ship_date
|
||||||
|
|
||||||
|
@ship_date.setter
|
||||||
|
def ship_date(self, ship_date):
|
||||||
|
|
||||||
|
self._ship_date = ship_date
|
||||||
|
|
||||||
|
@property
|
||||||
|
def status(self):
|
||||||
|
return self._status
|
||||||
|
|
||||||
|
@status.setter
|
||||||
|
def status(self, status):
|
||||||
|
allowed_values = ["placed", "approved", "delivered"]
|
||||||
|
if status not in allowed_values:
|
||||||
|
raise ValueError("Invalid value for `status`, must be one of {0}".format(allowed_values))
|
||||||
|
|
||||||
|
self._status = status
|
||||||
|
|
||||||
|
@property
|
||||||
|
def complete(self):
|
||||||
|
return self._complete
|
||||||
|
|
||||||
|
@complete.setter
|
||||||
|
def complete(self, complete):
|
||||||
|
|
||||||
|
self._complete = complete
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
properties = []
|
properties = []
|
||||||
for p in self.__dict__:
|
for p in self.__dict__:
|
||||||
|
@ -49,24 +49,81 @@ class Pet(object):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
self.id = None # int
|
self._id = None # int
|
||||||
|
|
||||||
|
|
||||||
self.category = None # Category
|
self._category = None # Category
|
||||||
|
|
||||||
|
|
||||||
self.name = None # str
|
self._name = None # str
|
||||||
|
|
||||||
|
|
||||||
self.photo_urls = None # list[str]
|
self._photo_urls = None # list[str]
|
||||||
|
|
||||||
|
|
||||||
self.tags = None # list[Tag]
|
self._tags = None # list[Tag]
|
||||||
|
|
||||||
# pet status in the store
|
# pet status in the store
|
||||||
self.status = None # str
|
self._status = None # str
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def id(self):
|
||||||
|
return self._id
|
||||||
|
|
||||||
|
@id.setter
|
||||||
|
def id(self, id):
|
||||||
|
|
||||||
|
self._id = id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def category(self):
|
||||||
|
return self._category
|
||||||
|
|
||||||
|
@category.setter
|
||||||
|
def category(self, category):
|
||||||
|
|
||||||
|
self._category = category
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@name.setter
|
||||||
|
def name(self, name):
|
||||||
|
|
||||||
|
self._name = name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def photo_urls(self):
|
||||||
|
return self._photo_urls
|
||||||
|
|
||||||
|
@photo_urls.setter
|
||||||
|
def photo_urls(self, photo_urls):
|
||||||
|
|
||||||
|
self._photo_urls = photo_urls
|
||||||
|
|
||||||
|
@property
|
||||||
|
def tags(self):
|
||||||
|
return self._tags
|
||||||
|
|
||||||
|
@tags.setter
|
||||||
|
def tags(self, tags):
|
||||||
|
|
||||||
|
self._tags = tags
|
||||||
|
|
||||||
|
@property
|
||||||
|
def status(self):
|
||||||
|
return self._status
|
||||||
|
|
||||||
|
@status.setter
|
||||||
|
def status(self, status):
|
||||||
|
allowed_values = ["available", "pending", "sold"]
|
||||||
|
if status not in allowed_values:
|
||||||
|
raise ValueError("Invalid value for `status`, must be one of {0}".format(allowed_values))
|
||||||
|
|
||||||
|
self._status = status
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
properties = []
|
properties = []
|
||||||
for p in self.__dict__:
|
for p in self.__dict__:
|
||||||
|
@ -41,12 +41,30 @@ class Tag(object):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
self.id = None # int
|
self._id = None # int
|
||||||
|
|
||||||
|
|
||||||
self.name = None # str
|
self._name = None # str
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def id(self):
|
||||||
|
return self._id
|
||||||
|
|
||||||
|
@id.setter
|
||||||
|
def id(self, id):
|
||||||
|
|
||||||
|
self._id = id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def name(self):
|
||||||
|
return self._name
|
||||||
|
|
||||||
|
@name.setter
|
||||||
|
def name(self, name):
|
||||||
|
|
||||||
|
self._name = name
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
properties = []
|
properties = []
|
||||||
for p in self.__dict__:
|
for p in self.__dict__:
|
||||||
|
@ -53,30 +53,102 @@ class User(object):
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
self.id = None # int
|
self._id = None # int
|
||||||
|
|
||||||
|
|
||||||
self.username = None # str
|
self._username = None # str
|
||||||
|
|
||||||
|
|
||||||
self.first_name = None # str
|
self._first_name = None # str
|
||||||
|
|
||||||
|
|
||||||
self.last_name = None # str
|
self._last_name = None # str
|
||||||
|
|
||||||
|
|
||||||
self.email = None # str
|
self._email = None # str
|
||||||
|
|
||||||
|
|
||||||
self.password = None # str
|
self._password = None # str
|
||||||
|
|
||||||
|
|
||||||
self.phone = None # str
|
self._phone = None # str
|
||||||
|
|
||||||
# User Status
|
# User Status
|
||||||
self.user_status = None # int
|
self._user_status = None # int
|
||||||
|
|
||||||
|
|
||||||
|
@property
|
||||||
|
def id(self):
|
||||||
|
return self._id
|
||||||
|
|
||||||
|
@id.setter
|
||||||
|
def id(self, id):
|
||||||
|
|
||||||
|
self._id = id
|
||||||
|
|
||||||
|
@property
|
||||||
|
def username(self):
|
||||||
|
return self._username
|
||||||
|
|
||||||
|
@username.setter
|
||||||
|
def username(self, username):
|
||||||
|
|
||||||
|
self._username = username
|
||||||
|
|
||||||
|
@property
|
||||||
|
def first_name(self):
|
||||||
|
return self._first_name
|
||||||
|
|
||||||
|
@first_name.setter
|
||||||
|
def first_name(self, first_name):
|
||||||
|
|
||||||
|
self._first_name = first_name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def last_name(self):
|
||||||
|
return self._last_name
|
||||||
|
|
||||||
|
@last_name.setter
|
||||||
|
def last_name(self, last_name):
|
||||||
|
|
||||||
|
self._last_name = last_name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def email(self):
|
||||||
|
return self._email
|
||||||
|
|
||||||
|
@email.setter
|
||||||
|
def email(self, email):
|
||||||
|
|
||||||
|
self._email = email
|
||||||
|
|
||||||
|
@property
|
||||||
|
def password(self):
|
||||||
|
return self._password
|
||||||
|
|
||||||
|
@password.setter
|
||||||
|
def password(self, password):
|
||||||
|
|
||||||
|
self._password = password
|
||||||
|
|
||||||
|
@property
|
||||||
|
def phone(self):
|
||||||
|
return self._phone
|
||||||
|
|
||||||
|
@phone.setter
|
||||||
|
def phone(self, phone):
|
||||||
|
|
||||||
|
self._phone = phone
|
||||||
|
|
||||||
|
@property
|
||||||
|
def user_status(self):
|
||||||
|
return self._user_status
|
||||||
|
|
||||||
|
@user_status.setter
|
||||||
|
def user_status(self, user_status):
|
||||||
|
|
||||||
|
self._user_status = user_status
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
properties = []
|
properties = []
|
||||||
for p in self.__dict__:
|
for p in self.__dict__:
|
||||||
|
25
samples/client/petstore/python/tests/test_order_model.py
Normal file
25
samples/client/petstore/python/tests/test_order_model.py
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
"""
|
||||||
|
Run the tests.
|
||||||
|
$ pip install nose (optional)
|
||||||
|
$ cd swagger_client-python
|
||||||
|
$ nosetests -v
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import time
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
import swagger_client
|
||||||
|
|
||||||
|
|
||||||
|
class OrderModelTests(unittest.TestCase):
|
||||||
|
|
||||||
|
def test_status(self):
|
||||||
|
order = swagger_client.Order()
|
||||||
|
order.status = "placed"
|
||||||
|
self.assertEqual("placed", order.status)
|
||||||
|
|
||||||
|
with self.assertRaises(ValueError):
|
||||||
|
order.status = "invalid"
|
Loading…
Reference in New Issue
Block a user