mirror of
				https://github.com/OpenAPITools/openapi-generator.git
				synced 2025-10-31 08:43:45 +00:00 
			
		
		
		
	[cpp-rest-sdk] fix enum values being used instead of names (#21223)
* [cpp-rest-sdk] fix enum values being used instead of names * [cpp-rest-sdk] remove unnecessary prefix for enum classes * [cpprest-sdk]: use _XPLATSTR for string_t on Windows
This commit is contained in:
		
							parent
							
								
									fc29daa6c0
								
							
						
					
					
						commit
						6e9dedba75
					
				| @ -123,7 +123,7 @@ public: | |||||||
|         /// {{.}} |         /// {{.}} | ||||||
|         /// </summary> |         /// </summary> | ||||||
|         {{/enumDescription}} |         {{/enumDescription}} | ||||||
|         {{classname}}_{{{name}}}{{^last}},{{/last}} |         {{{name}}}{{^last}},{{/last}} | ||||||
|         {{/enumVars}} |         {{/enumVars}} | ||||||
|         {{/allowableValues}} |         {{/allowableValues}} | ||||||
|     }; |     }; | ||||||
| @ -136,14 +136,14 @@ public: | |||||||
|         std::map<e{{classname}},utility::string_t> enumToStrMap = { |         std::map<e{{classname}},utility::string_t> enumToStrMap = { | ||||||
|         {{#allowableValues}} |         {{#allowableValues}} | ||||||
|         {{#enumVars}} |         {{#enumVars}} | ||||||
|         { e{{classname}}::{{classname}}_{{{name}}}, "{{{name}}}" }{{^-last}},{{/-last}} |         { e{{classname}}::{{{name}}}, _XPLATSTR("{{{name}}}") }{{^-last}},{{/-last}} | ||||||
|         {{/enumVars}} |         {{/enumVars}} | ||||||
|         {{/allowableValues}} |         {{/allowableValues}} | ||||||
| }; | }; | ||||||
|         std::map<utility::string_t,e{{classname}}> strToEnumMap = { |         std::map<utility::string_t,e{{classname}}> strToEnumMap = { | ||||||
|         {{#allowableValues}} |         {{#allowableValues}} | ||||||
|         {{#enumVars}} |         {{#enumVars}} | ||||||
|         { "{{{name}}}", e{{classname}}::{{classname}}_{{{name}}} }{{^-last}},{{/-last}} |         { _XPLATSTR("{{{name}}}"), e{{classname}}::{{{name}}} }{{^-last}},{{/-last}} | ||||||
|         {{/enumVars}} |         {{/enumVars}} | ||||||
|         {{/allowableValues}} |         {{/allowableValues}} | ||||||
| }; | }; | ||||||
| @ -185,8 +185,11 @@ public: | |||||||
|     {{#isEnum}} |     {{#isEnum}} | ||||||
|     enum class {{#isContainer}}{{{enumName}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}{{/isContainer}} |     enum class {{#isContainer}}{{{enumName}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}{{/isContainer}} | ||||||
|     { |     { | ||||||
|         {{#allowableValues}}{{#enumVars}}{{value}}, |         {{#allowableValues}} | ||||||
|         {{/enumVars}}{{/allowableValues}} |         {{#enumVars}} | ||||||
|  |         {{{name}}}{{^last}},{{/last}} | ||||||
|  |         {{/enumVars}} | ||||||
|  |         {{/allowableValues}} | ||||||
|     }; |     }; | ||||||
|     {{#description}} |     {{#description}} | ||||||
|     /// <summary> |     /// <summary> | ||||||
|  | |||||||
| @ -72,7 +72,7 @@ using EnumUnderlyingType = {{#isNumeric}}int64_t{{/isNumeric}}{{^isNumeric}}util | |||||||
|     { |     { | ||||||
|     {{#enumVars}} |     {{#enumVars}} | ||||||
|     case {{value}}: |     case {{value}}: | ||||||
|         return {{classname}}::e{{classname}}::{{classname}}_{{name}}; |         return {{classname}}::e{{classname}}::{{name}}; | ||||||
|     {{#-last}} |     {{#-last}} | ||||||
|     default: |     default: | ||||||
|         break; |         break; | ||||||
| @ -83,7 +83,7 @@ using EnumUnderlyingType = {{#isNumeric}}int64_t{{/isNumeric}}{{^isNumeric}}util | |||||||
| {{^isNumeric}} | {{^isNumeric}} | ||||||
|     {{#enumVars}} |     {{#enumVars}} | ||||||
|     if (val == utility::conversions::to_string_t(_XPLATSTR("{{{value}}}"))) |     if (val == utility::conversions::to_string_t(_XPLATSTR("{{{value}}}"))) | ||||||
|         return {{classname}}::e{{classname}}::{{classname}}_{{name}}; |         return {{classname}}::e{{classname}}::{{name}}; | ||||||
|     {{/enumVars}} |     {{/enumVars}} | ||||||
| {{/isNumeric}} | {{/isNumeric}} | ||||||
| {{/allowableValues}} | {{/allowableValues}} | ||||||
| @ -96,7 +96,7 @@ EnumUnderlyingType fromEnum({{classname}}::e{{classname}} e) | |||||||
|     switch (e) |     switch (e) | ||||||
|     { |     { | ||||||
| {{#enumVars}} | {{#enumVars}} | ||||||
|     case {{classname}}::e{{classname}}::{{classname}}_{{name}}: |     case {{classname}}::e{{classname}}::{{name}}: | ||||||
|         return {{#isNumeric}}{{value}}{{/isNumeric}}{{^isNumeric}}_XPLATSTR("{{value}}"){{/isNumeric}}; |         return {{#isNumeric}}{{value}}{{/isNumeric}}{{^isNumeric}}_XPLATSTR("{{value}}"){{/isNumeric}}; | ||||||
| {{#-last}} | {{#-last}} | ||||||
|     default: |     default: | ||||||
| @ -354,7 +354,7 @@ bool {{classname}}::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, | |||||||
| { | { | ||||||
|     {{#allowableValues}}{{#enumVars}} |     {{#allowableValues}}{{#enumVars}} | ||||||
|     if (value == utility::conversions::to_string_t("{{value}}")) { |     if (value == utility::conversions::to_string_t("{{value}}")) { | ||||||
|         return {{#isContainer}}{{{enumName}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}{{/isContainer}}::{{value}}; |         return {{#isContainer}}{{{enumName}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}{{/isContainer}}::{{name}}; | ||||||
|     } |     } | ||||||
|     {{/enumVars}}{{/allowableValues}} |     {{/enumVars}}{{/allowableValues}} | ||||||
|     throw std::invalid_argument("Invalid value for conversion to {{{datatypeWithEnum}}}"); |     throw std::invalid_argument("Invalid value for conversion to {{{datatypeWithEnum}}}"); | ||||||
| @ -369,7 +369,7 @@ const {{dataType}} {{classname}}::from{{{datatypeWithEnum}}}(const {{{datatypeWi | |||||||
|     switch(value) |     switch(value) | ||||||
|     { |     { | ||||||
|         {{#allowableValues}}{{#enumVars}} |         {{#allowableValues}}{{#enumVars}} | ||||||
|         case {{#isContainer}}{{{enumName}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}{{/isContainer}}::{{value}}: return utility::conversions::to_string_t("{{value}}"); |         case {{#isContainer}}{{{enumName}}}{{/isContainer}}{{^isContainer}}{{{datatypeWithEnum}}}{{/isContainer}}::{{name}}: return utility::conversions::to_string_t("{{value}}"); | ||||||
|         {{/enumVars}}{{/allowableValues}} |         {{/enumVars}}{{/allowableValues}} | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -54,11 +54,11 @@ public: | |||||||
| 
 | 
 | ||||||
|     enum class eColor |     enum class eColor | ||||||
|     { |     { | ||||||
|         Color_BLACK, |         BLACK, | ||||||
|         Color_WHITE, |         WHITE, | ||||||
|         Color_BROWN, |         BROWN, | ||||||
|         Color_GOLDEN, |         GOLDEN, | ||||||
|         Color_MIXED, |         MIXED, | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|     eColor getValue() const; |     eColor getValue() const; | ||||||
| @ -67,18 +67,18 @@ public: | |||||||
|     protected: |     protected: | ||||||
|         eColor m_value; |         eColor m_value; | ||||||
|         std::map<eColor,utility::string_t> enumToStrMap = { |         std::map<eColor,utility::string_t> enumToStrMap = { | ||||||
|         { eColor::Color_BLACK, "BLACK" }, |         { eColor::BLACK, _XPLATSTR("BLACK") }, | ||||||
|         { eColor::Color_WHITE, "WHITE" }, |         { eColor::WHITE, _XPLATSTR("WHITE") }, | ||||||
|         { eColor::Color_BROWN, "BROWN" }, |         { eColor::BROWN, _XPLATSTR("BROWN") }, | ||||||
|         { eColor::Color_GOLDEN, "GOLDEN" }, |         { eColor::GOLDEN, _XPLATSTR("GOLDEN") }, | ||||||
|         { eColor::Color_MIXED, "MIXED" } |         { eColor::MIXED, _XPLATSTR("MIXED") } | ||||||
| }; | }; | ||||||
|         std::map<utility::string_t,eColor> strToEnumMap = { |         std::map<utility::string_t,eColor> strToEnumMap = { | ||||||
|         { "BLACK", eColor::Color_BLACK }, |         { _XPLATSTR("BLACK"), eColor::BLACK }, | ||||||
|         { "WHITE", eColor::Color_WHITE }, |         { _XPLATSTR("WHITE"), eColor::WHITE }, | ||||||
|         { "BROWN", eColor::Color_BROWN }, |         { _XPLATSTR("BROWN"), eColor::BROWN }, | ||||||
|         { "GOLDEN", eColor::Color_GOLDEN }, |         { _XPLATSTR("GOLDEN"), eColor::GOLDEN }, | ||||||
|         { "MIXED", eColor::Color_MIXED } |         { _XPLATSTR("MIXED"), eColor::MIXED } | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| }; | }; | ||||||
|  | |||||||
| @ -58,10 +58,9 @@ public: | |||||||
| 
 | 
 | ||||||
|     enum class StatusEnum |     enum class StatusEnum | ||||||
|     { |     { | ||||||
|         placed, |         PLACED, | ||||||
|         approved, |         APPROVED, | ||||||
|         delivered, |         DELIVERED, | ||||||
|          |  | ||||||
|     }; |     }; | ||||||
|     /// <summary>
 |     /// <summary>
 | ||||||
|     /// Order Status
 |     /// Order Status
 | ||||||
|  | |||||||
| @ -64,10 +64,9 @@ public: | |||||||
| 
 | 
 | ||||||
|     enum class StatusEnum |     enum class StatusEnum | ||||||
|     { |     { | ||||||
|         available, |         AVAILABLE, | ||||||
|         pending, |         PENDING, | ||||||
|         sold, |         SOLD, | ||||||
|          |  | ||||||
|     }; |     }; | ||||||
|     /// <summary>
 |     /// <summary>
 | ||||||
|     /// pet status in the store
 |     /// pet status in the store
 | ||||||
|  | |||||||
| @ -25,15 +25,15 @@ using EnumUnderlyingType = utility::string_t; | |||||||
| Color::eColor toEnum(const EnumUnderlyingType& val) | Color::eColor toEnum(const EnumUnderlyingType& val) | ||||||
| { | { | ||||||
|     if (val == utility::conversions::to_string_t(_XPLATSTR("black"))) |     if (val == utility::conversions::to_string_t(_XPLATSTR("black"))) | ||||||
|         return Color::eColor::Color_BLACK; |         return Color::eColor::BLACK; | ||||||
|     if (val == utility::conversions::to_string_t(_XPLATSTR("white"))) |     if (val == utility::conversions::to_string_t(_XPLATSTR("white"))) | ||||||
|         return Color::eColor::Color_WHITE; |         return Color::eColor::WHITE; | ||||||
|     if (val == utility::conversions::to_string_t(_XPLATSTR("brown"))) |     if (val == utility::conversions::to_string_t(_XPLATSTR("brown"))) | ||||||
|         return Color::eColor::Color_BROWN; |         return Color::eColor::BROWN; | ||||||
|     if (val == utility::conversions::to_string_t(_XPLATSTR("golden"))) |     if (val == utility::conversions::to_string_t(_XPLATSTR("golden"))) | ||||||
|         return Color::eColor::Color_GOLDEN; |         return Color::eColor::GOLDEN; | ||||||
|     if (val == utility::conversions::to_string_t(_XPLATSTR("mixed"))) |     if (val == utility::conversions::to_string_t(_XPLATSTR("mixed"))) | ||||||
|         return Color::eColor::Color_MIXED; |         return Color::eColor::MIXED; | ||||||
|     return {}; |     return {}; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -41,15 +41,15 @@ EnumUnderlyingType fromEnum(Color::eColor e) | |||||||
| { | { | ||||||
|     switch (e) |     switch (e) | ||||||
|     { |     { | ||||||
|     case Color::eColor::Color_BLACK: |     case Color::eColor::BLACK: | ||||||
|         return _XPLATSTR("black"); |         return _XPLATSTR("black"); | ||||||
|     case Color::eColor::Color_WHITE: |     case Color::eColor::WHITE: | ||||||
|         return _XPLATSTR("white"); |         return _XPLATSTR("white"); | ||||||
|     case Color::eColor::Color_BROWN: |     case Color::eColor::BROWN: | ||||||
|         return _XPLATSTR("brown"); |         return _XPLATSTR("brown"); | ||||||
|     case Color::eColor::Color_GOLDEN: |     case Color::eColor::GOLDEN: | ||||||
|         return _XPLATSTR("golden"); |         return _XPLATSTR("golden"); | ||||||
|     case Color::eColor::Color_MIXED: |     case Color::eColor::MIXED: | ||||||
|         return _XPLATSTR("mixed"); |         return _XPLATSTR("mixed"); | ||||||
|     default: |     default: | ||||||
|         break; |         break; | ||||||
|  | |||||||
| @ -239,15 +239,15 @@ Order::StatusEnum Order::toStatusEnum(const utility::string_t& value) const | |||||||
| { | { | ||||||
|      |      | ||||||
|     if (value == utility::conversions::to_string_t("placed")) { |     if (value == utility::conversions::to_string_t("placed")) { | ||||||
|         return StatusEnum::placed; |         return StatusEnum::PLACED; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     if (value == utility::conversions::to_string_t("approved")) { |     if (value == utility::conversions::to_string_t("approved")) { | ||||||
|         return StatusEnum::approved; |         return StatusEnum::APPROVED; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     if (value == utility::conversions::to_string_t("delivered")) { |     if (value == utility::conversions::to_string_t("delivered")) { | ||||||
|         return StatusEnum::delivered; |         return StatusEnum::DELIVERED; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     throw std::invalid_argument("Invalid value for conversion to StatusEnum"); |     throw std::invalid_argument("Invalid value for conversion to StatusEnum"); | ||||||
| @ -259,11 +259,11 @@ const utility::string_t Order::fromStatusEnum(const StatusEnum value) const | |||||||
|     switch(value) |     switch(value) | ||||||
|     { |     { | ||||||
|          |          | ||||||
|         case StatusEnum::placed: return utility::conversions::to_string_t("placed"); |         case StatusEnum::PLACED: return utility::conversions::to_string_t("placed"); | ||||||
|          |          | ||||||
|         case StatusEnum::approved: return utility::conversions::to_string_t("approved"); |         case StatusEnum::APPROVED: return utility::conversions::to_string_t("approved"); | ||||||
|          |          | ||||||
|         case StatusEnum::delivered: return utility::conversions::to_string_t("delivered"); |         case StatusEnum::DELIVERED: return utility::conversions::to_string_t("delivered"); | ||||||
|          |          | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
| @ -263,15 +263,15 @@ Pet::StatusEnum Pet::toStatusEnum(const utility::string_t& value) const | |||||||
| { | { | ||||||
|      |      | ||||||
|     if (value == utility::conversions::to_string_t("available")) { |     if (value == utility::conversions::to_string_t("available")) { | ||||||
|         return StatusEnum::available; |         return StatusEnum::AVAILABLE; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     if (value == utility::conversions::to_string_t("pending")) { |     if (value == utility::conversions::to_string_t("pending")) { | ||||||
|         return StatusEnum::pending; |         return StatusEnum::PENDING; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     if (value == utility::conversions::to_string_t("sold")) { |     if (value == utility::conversions::to_string_t("sold")) { | ||||||
|         return StatusEnum::sold; |         return StatusEnum::SOLD; | ||||||
|     } |     } | ||||||
|      |      | ||||||
|     throw std::invalid_argument("Invalid value for conversion to StatusEnum"); |     throw std::invalid_argument("Invalid value for conversion to StatusEnum"); | ||||||
| @ -283,11 +283,11 @@ const utility::string_t Pet::fromStatusEnum(const StatusEnum value) const | |||||||
|     switch(value) |     switch(value) | ||||||
|     { |     { | ||||||
|          |          | ||||||
|         case StatusEnum::available: return utility::conversions::to_string_t("available"); |         case StatusEnum::AVAILABLE: return utility::conversions::to_string_t("available"); | ||||||
|          |          | ||||||
|         case StatusEnum::pending: return utility::conversions::to_string_t("pending"); |         case StatusEnum::PENDING: return utility::conversions::to_string_t("pending"); | ||||||
|          |          | ||||||
|         case StatusEnum::sold: return utility::conversions::to_string_t("sold"); |         case StatusEnum::SOLD: return utility::conversions::to_string_t("sold"); | ||||||
|          |          | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user