From 652b0f5bf669601702cceabdee6a9da78d2de2bd Mon Sep 17 00:00:00 2001 From: Arun Date: Thu, 24 Oct 2019 14:58:29 +0530 Subject: [PATCH] [python] Add ability to get allowed values (#4138) * Add function to get list of allowed values * [python] Add function to get list of allowed values * Remove temporary variable * Remove static method and use a variable * Remove classname --- .../src/main/resources/python/model.mustache | 4 ++++ .../client/petstore/python/petstore_api/models/enum_class.py | 2 ++ .../client/petstore/python/petstore_api/models/outer_enum.py | 2 ++ .../client/petstore/python/petstore_api/models/enum_class.py | 2 ++ .../client/petstore/python/petstore_api/models/outer_enum.py | 2 ++ .../python/petstore_api/models/outer_enum_default_value.py | 2 ++ .../petstore/python/petstore_api/models/outer_enum_integer.py | 2 ++ .../petstore_api/models/outer_enum_integer_default_value.py | 2 ++ 8 files changed, 18 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/python/model.mustache b/modules/openapi-generator/src/main/resources/python/model.mustache index 17264bb46b0d..70f6e7489a7e 100644 --- a/modules/openapi-generator/src/main/resources/python/model.mustache +++ b/modules/openapi-generator/src/main/resources/python/model.mustache @@ -27,6 +27,10 @@ class {{classname}}(object): {{/-last}} {{/enumVars}}{{/allowableValues}} +{{#allowableValues}} + allowable_values = [{{#enumVars}}{{name}}{{^-last}}, {{/-last}}{{/enumVars}}] # noqa: E501 + +{{/allowableValues}} """ Attributes: openapi_types (dict): The key is attribute name diff --git a/samples/client/petstore/python/petstore_api/models/enum_class.py b/samples/client/petstore/python/petstore_api/models/enum_class.py index 8bc627578608..0df679d29f4c 100644 --- a/samples/client/petstore/python/petstore_api/models/enum_class.py +++ b/samples/client/petstore/python/petstore_api/models/enum_class.py @@ -32,6 +32,8 @@ class EnumClass(object): _EFG = "-efg" _XYZ_ = "(xyz)" + allowable_values = [_ABC, _EFG, _XYZ_] # noqa: E501 + """ Attributes: openapi_types (dict): The key is attribute name diff --git a/samples/client/petstore/python/petstore_api/models/outer_enum.py b/samples/client/petstore/python/petstore_api/models/outer_enum.py index 8fbfeb7aaea5..bcea632b3f5b 100644 --- a/samples/client/petstore/python/petstore_api/models/outer_enum.py +++ b/samples/client/petstore/python/petstore_api/models/outer_enum.py @@ -32,6 +32,8 @@ class OuterEnum(object): APPROVED = "approved" DELIVERED = "delivered" + allowable_values = [PLACED, APPROVED, DELIVERED] # noqa: E501 + """ Attributes: openapi_types (dict): The key is attribute name diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/enum_class.py b/samples/openapi3/client/petstore/python/petstore_api/models/enum_class.py index 8bc627578608..0df679d29f4c 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/enum_class.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/enum_class.py @@ -32,6 +32,8 @@ class EnumClass(object): _EFG = "-efg" _XYZ_ = "(xyz)" + allowable_values = [_ABC, _EFG, _XYZ_] # noqa: E501 + """ Attributes: openapi_types (dict): The key is attribute name diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum.py b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum.py index 8fbfeb7aaea5..bcea632b3f5b 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum.py @@ -32,6 +32,8 @@ class OuterEnum(object): APPROVED = "approved" DELIVERED = "delivered" + allowable_values = [PLACED, APPROVED, DELIVERED] # noqa: E501 + """ Attributes: openapi_types (dict): The key is attribute name diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_default_value.py b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_default_value.py index 881edd1384f8..e448af3c8ccd 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_default_value.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_default_value.py @@ -32,6 +32,8 @@ class OuterEnumDefaultValue(object): APPROVED = "approved" DELIVERED = "delivered" + allowable_values = [PLACED, APPROVED, DELIVERED] # noqa: E501 + """ Attributes: openapi_types (dict): The key is attribute name diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer.py b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer.py index 8e6d0c44b081..7047cd72c51a 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer.py @@ -32,6 +32,8 @@ class OuterEnumInteger(object): _1 = "1" _2 = "2" + allowable_values = [_0, _1, _2] # noqa: E501 + """ Attributes: openapi_types (dict): The key is attribute name diff --git a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer_default_value.py b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer_default_value.py index 943ad3b596c1..f7a0ef3095b1 100644 --- a/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer_default_value.py +++ b/samples/openapi3/client/petstore/python/petstore_api/models/outer_enum_integer_default_value.py @@ -32,6 +32,8 @@ class OuterEnumIntegerDefaultValue(object): _1 = "1" _2 = "2" + allowable_values = [_0, _1, _2] # noqa: E501 + """ Attributes: openapi_types (dict): The key is attribute name