Skip to content

Commit 3048fb0

Browse files
authored
[cpp-rest-sdk] remove U macro definition from public headers (#21221)
Cpprest has a public U macro definition that causes build errors in libraries as U is a common name for template parameters. This PR fixes the issue by turning it off. [microsoft/cpprestsdk@411a109/Release/include/cpprest/details/basic_types.h#L87](https://github.com/microsoft/cpprestsdk/blob/411a109150b270f23c8c97fa4ec9a0a4a98cdecf/Release/include/cpprest/details/basic_types.h#L87) Related to microsoft/cpprestsdk#1805 and fmtlib/fmt#4180
1 parent 5117616 commit 3048fb0

File tree

14 files changed

+265
-386
lines changed

14 files changed

+265
-386
lines changed

modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/cmake-lists.mustache

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ if(NOT CMAKE_BUILD_TYPE)
3636
endif()
3737

3838
find_package(cpprestsdk REQUIRED)
39+
target_compile_definitions(cpprestsdk::cpprest INTERFACE _TURN_OFF_PLATFORM_STRING)
3940
find_package(Boost REQUIRED)
4041

4142
include(GNUInstallDirs)

modules/openapi-generator/src/main/resources/cpp-rest-sdk-client/model-source.mustache

+21-21
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ using EnumUnderlyingType = {{#isNumeric}}int64_t{{/isNumeric}}{{^isNumeric}}util
8282
{{/isNumeric}}
8383
{{^isNumeric}}
8484
{{#enumVars}}
85-
if (val == utility::conversions::to_string_t(U("{{{value}}}")))
85+
if (val == utility::conversions::to_string_t(_XPLATSTR("{{{value}}}")))
8686
return {{classname}}::e{{classname}}::{{classname}}_{{name}};
8787
{{/enumVars}}
8888
{{/isNumeric}}
@@ -97,7 +97,7 @@ EnumUnderlyingType fromEnum({{classname}}::e{{classname}} e)
9797
{
9898
{{#enumVars}}
9999
case {{classname}}::e{{classname}}::{{classname}}_{{name}}:
100-
return {{#isNumeric}}{{value}}{{/isNumeric}}{{^isNumeric}}U("{{value}}"){{/isNumeric}};
100+
return {{#isNumeric}}{{value}}{{/isNumeric}}{{^isNumeric}}_XPLATSTR("{{value}}"){{/isNumeric}};
101101
{{#-last}}
102102
default:
103103
break;
@@ -137,9 +137,9 @@ bool {{classname}}::fromJson(const web::json::value& val)
137137
void {{classname}}::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix) const
138138
{
139139
utility::string_t namePrefix = prefix;
140-
if (!namePrefix.empty() && namePrefix.back() != U('.'))
140+
if (!namePrefix.empty() && namePrefix.back() != _XPLATSTR('.'))
141141
{
142-
namePrefix.push_back(U('.'));
142+
namePrefix.push_back(_XPLATSTR('.'));
143143
}
144144

145145
auto e = fromEnum(m_value);
@@ -150,9 +150,9 @@ bool {{classname}}::fromMultiPart(std::shared_ptr<MultipartFormData> multipart,
150150
{
151151
bool ok = true;
152152
utility::string_t namePrefix = prefix;
153-
if (!namePrefix.empty() && namePrefix.back() != U('.'))
153+
if (!namePrefix.empty() && namePrefix.back() != _XPLATSTR('.'))
154154
{
155-
namePrefix.push_back(U('.'));
155+
namePrefix.push_back(_XPLATSTR('.'));
156156
}
157157
{
158158
EnumUnderlyingType e;
@@ -231,13 +231,13 @@ web::json::value {{classname}}::toJson() const
231231
{{#isEnum}}{{#isContainer}}{{#isArray}}
232232
{{{dataType}}} refVal = from{{{enumName}}}(m_{{name}});
233233
{{/isArray}}{{#isMap}}
234-
val[utility::conversions::to_string_t(U("{{baseName}}"))] = ModelBase::toJson(m_{{name}});
234+
val[utility::conversions::to_string_t(_XPLATSTR("{{baseName}}"))] = ModelBase::toJson(m_{{name}});
235235
{{/isMap}}{{/isContainer}}{{^isContainer}}
236236
utility::string_t refVal = from{{{datatypeWithEnum}}}(m_{{name}});
237-
{{/isContainer}}{{^isMap}}val[utility::conversions::to_string_t(U("{{baseName}}"))] = ModelBase::toJson(refVal);
237+
{{/isContainer}}{{^isMap}}val[utility::conversions::to_string_t(_XPLATSTR("{{baseName}}"))] = ModelBase::toJson(refVal);
238238
{{/isMap}}{{/isEnum}}
239239
{{^isEnum}}
240-
val[utility::conversions::to_string_t(U("{{baseName}}"))] = ModelBase::toJson(m_{{name}});
240+
val[utility::conversions::to_string_t(_XPLATSTR("{{baseName}}"))] = ModelBase::toJson(m_{{name}});
241241
{{/isEnum}}
242242
}
243243
{{/isInherited}}
@@ -254,9 +254,9 @@ bool {{classname}}::fromJson(const web::json::value& val)
254254
{{/parent}}
255255
{{#vars}}
256256
{{^isInherited}}
257-
if(val.has_field(utility::conversions::to_string_t(U("{{baseName}}"))))
257+
if(val.has_field(utility::conversions::to_string_t(_XPLATSTR("{{baseName}}"))))
258258
{
259-
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t(U("{{baseName}}")));
259+
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t(_XPLATSTR("{{baseName}}")));
260260
if(!fieldValue.is_null())
261261
{
262262
{{{dataType}}} refVal_{{setter}};
@@ -281,26 +281,26 @@ bool {{classname}}::fromJson(const web::json::value& val)
281281
void {{classname}}::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix) const
282282
{
283283
utility::string_t namePrefix = prefix;
284-
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t(U(".")))
284+
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t(_XPLATSTR(".")))
285285
{
286-
namePrefix += utility::conversions::to_string_t(U("."));
286+
namePrefix += utility::conversions::to_string_t(_XPLATSTR("."));
287287
}
288288
{{#vars}}
289289
if(m_{{name}}IsSet)
290290
{
291291
{{^isEnum}}
292-
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(U("{{baseName}}")), m_{{name}}));
292+
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(_XPLATSTR("{{baseName}}")), m_{{name}}));
293293
{{/isEnum}}
294294
{{#isEnum}}
295295
{{#isContainer}}
296296
{{#isArray}}
297-
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(U("{{baseName}}")), from{{{enumName}}}(m_{{name}})));
297+
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(_XPLATSTR("{{baseName}}")), from{{{enumName}}}(m_{{name}})));
298298
{{/isArray}}{{#isMap}}
299-
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(U("{{baseName}}")), m_{{name}}));
299+
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(_XPLATSTR("{{baseName}}")), m_{{name}}));
300300
{{/isMap}}
301301
{{/isContainer}}
302302
{{^isContainer}}
303-
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(U("{{baseName}}")), from{{{datatypeWithEnum}}}(m_{{name}})));
303+
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(_XPLATSTR("{{baseName}}")), from{{{datatypeWithEnum}}}(m_{{name}})));
304304
{{/isContainer}}
305305
{{/isEnum}}
306306
}
@@ -311,16 +311,16 @@ bool {{classname}}::fromMultiPart(std::shared_ptr<MultipartFormData> multipart,
311311
{
312312
bool ok = true;
313313
utility::string_t namePrefix = prefix;
314-
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t(U(".")))
314+
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t(_XPLATSTR(".")))
315315
{
316-
namePrefix += utility::conversions::to_string_t(U("."));
316+
namePrefix += utility::conversions::to_string_t(_XPLATSTR("."));
317317
}
318318

319319
{{#vars}}
320-
if(multipart->hasContent(utility::conversions::to_string_t(U("{{baseName}}"))))
320+
if(multipart->hasContent(utility::conversions::to_string_t(_XPLATSTR("{{baseName}}"))))
321321
{
322322
{{{dataType}}} refVal_{{setter}};
323-
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t(U("{{baseName}}"))), refVal_{{setter}} );
323+
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t(_XPLATSTR("{{baseName}}"))), refVal_{{setter}} );
324324
{{^isEnum}}
325325
{{setter}}(refVal_{{setter}});
326326
{{/isEnum}}

samples/client/petstore/cpp-restsdk/client/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ if(NOT CMAKE_BUILD_TYPE)
3636
endif()
3737

3838
find_package(cpprestsdk REQUIRED)
39+
target_compile_definitions(cpprestsdk::cpprest INTERFACE _TURN_OFF_PLATFORM_STRING)
3940
find_package(Boost REQUIRED)
4041

4142
include(GNUInstallDirs)

samples/client/petstore/cpp-restsdk/client/src/model/ApiResponse.cpp

+22-22
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@ web::json::value ApiResponse::toJson() const
4343
if(m_CodeIsSet)
4444
{
4545

46-
val[utility::conversions::to_string_t(U("code"))] = ModelBase::toJson(m_Code);
46+
val[utility::conversions::to_string_t(_XPLATSTR("code"))] = ModelBase::toJson(m_Code);
4747
}
4848
if(m_TypeIsSet)
4949
{
5050

51-
val[utility::conversions::to_string_t(U("type"))] = ModelBase::toJson(m_Type);
51+
val[utility::conversions::to_string_t(_XPLATSTR("type"))] = ModelBase::toJson(m_Type);
5252
}
5353
if(m_MessageIsSet)
5454
{
5555

56-
val[utility::conversions::to_string_t(U("message"))] = ModelBase::toJson(m_Message);
56+
val[utility::conversions::to_string_t(_XPLATSTR("message"))] = ModelBase::toJson(m_Message);
5757
}
5858

5959
return val;
@@ -62,9 +62,9 @@ web::json::value ApiResponse::toJson() const
6262
bool ApiResponse::fromJson(const web::json::value& val)
6363
{
6464
bool ok = true;
65-
if(val.has_field(utility::conversions::to_string_t(U("code"))))
65+
if(val.has_field(utility::conversions::to_string_t(_XPLATSTR("code"))))
6666
{
67-
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t(U("code")));
67+
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t(_XPLATSTR("code")));
6868
if(!fieldValue.is_null())
6969
{
7070
int32_t refVal_setCode;
@@ -73,9 +73,9 @@ bool ApiResponse::fromJson(const web::json::value& val)
7373

7474
}
7575
}
76-
if(val.has_field(utility::conversions::to_string_t(U("type"))))
76+
if(val.has_field(utility::conversions::to_string_t(_XPLATSTR("type"))))
7777
{
78-
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t(U("type")));
78+
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t(_XPLATSTR("type")));
7979
if(!fieldValue.is_null())
8080
{
8181
utility::string_t refVal_setType;
@@ -84,9 +84,9 @@ bool ApiResponse::fromJson(const web::json::value& val)
8484

8585
}
8686
}
87-
if(val.has_field(utility::conversions::to_string_t(U("message"))))
87+
if(val.has_field(utility::conversions::to_string_t(_XPLATSTR("message"))))
8888
{
89-
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t(U("message")));
89+
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t(_XPLATSTR("message")));
9090
if(!fieldValue.is_null())
9191
{
9292
utility::string_t refVal_setMessage;
@@ -101,49 +101,49 @@ bool ApiResponse::fromJson(const web::json::value& val)
101101
void ApiResponse::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix) const
102102
{
103103
utility::string_t namePrefix = prefix;
104-
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t(U(".")))
104+
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t(_XPLATSTR(".")))
105105
{
106-
namePrefix += utility::conversions::to_string_t(U("."));
106+
namePrefix += utility::conversions::to_string_t(_XPLATSTR("."));
107107
}
108108
if(m_CodeIsSet)
109109
{
110-
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(U("code")), m_Code));
110+
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(_XPLATSTR("code")), m_Code));
111111
}
112112
if(m_TypeIsSet)
113113
{
114-
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(U("type")), m_Type));
114+
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(_XPLATSTR("type")), m_Type));
115115
}
116116
if(m_MessageIsSet)
117117
{
118-
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(U("message")), m_Message));
118+
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(_XPLATSTR("message")), m_Message));
119119
}
120120
}
121121

122122
bool ApiResponse::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
123123
{
124124
bool ok = true;
125125
utility::string_t namePrefix = prefix;
126-
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t(U(".")))
126+
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t(_XPLATSTR(".")))
127127
{
128-
namePrefix += utility::conversions::to_string_t(U("."));
128+
namePrefix += utility::conversions::to_string_t(_XPLATSTR("."));
129129
}
130130

131-
if(multipart->hasContent(utility::conversions::to_string_t(U("code"))))
131+
if(multipart->hasContent(utility::conversions::to_string_t(_XPLATSTR("code"))))
132132
{
133133
int32_t refVal_setCode;
134-
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t(U("code"))), refVal_setCode );
134+
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t(_XPLATSTR("code"))), refVal_setCode );
135135
setCode(refVal_setCode);
136136
}
137-
if(multipart->hasContent(utility::conversions::to_string_t(U("type"))))
137+
if(multipart->hasContent(utility::conversions::to_string_t(_XPLATSTR("type"))))
138138
{
139139
utility::string_t refVal_setType;
140-
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t(U("type"))), refVal_setType );
140+
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t(_XPLATSTR("type"))), refVal_setType );
141141
setType(refVal_setType);
142142
}
143-
if(multipart->hasContent(utility::conversions::to_string_t(U("message"))))
143+
if(multipart->hasContent(utility::conversions::to_string_t(_XPLATSTR("message"))))
144144
{
145145
utility::string_t refVal_setMessage;
146-
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t(U("message"))), refVal_setMessage );
146+
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t(_XPLATSTR("message"))), refVal_setMessage );
147147
setMessage(refVal_setMessage);
148148
}
149149
return ok;

samples/client/petstore/cpp-restsdk/client/src/model/Category.cpp

+16-16
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,12 @@ web::json::value Category::toJson() const
4141
if(m_IdIsSet)
4242
{
4343

44-
val[utility::conversions::to_string_t(U("id"))] = ModelBase::toJson(m_Id);
44+
val[utility::conversions::to_string_t(_XPLATSTR("id"))] = ModelBase::toJson(m_Id);
4545
}
4646
if(m_NameIsSet)
4747
{
4848

49-
val[utility::conversions::to_string_t(U("name"))] = ModelBase::toJson(m_Name);
49+
val[utility::conversions::to_string_t(_XPLATSTR("name"))] = ModelBase::toJson(m_Name);
5050
}
5151

5252
return val;
@@ -55,9 +55,9 @@ web::json::value Category::toJson() const
5555
bool Category::fromJson(const web::json::value& val)
5656
{
5757
bool ok = true;
58-
if(val.has_field(utility::conversions::to_string_t(U("id"))))
58+
if(val.has_field(utility::conversions::to_string_t(_XPLATSTR("id"))))
5959
{
60-
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t(U("id")));
60+
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t(_XPLATSTR("id")));
6161
if(!fieldValue.is_null())
6262
{
6363
int64_t refVal_setId;
@@ -66,9 +66,9 @@ bool Category::fromJson(const web::json::value& val)
6666

6767
}
6868
}
69-
if(val.has_field(utility::conversions::to_string_t(U("name"))))
69+
if(val.has_field(utility::conversions::to_string_t(_XPLATSTR("name"))))
7070
{
71-
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t(U("name")));
71+
const web::json::value& fieldValue = val.at(utility::conversions::to_string_t(_XPLATSTR("name")));
7272
if(!fieldValue.is_null())
7373
{
7474
utility::string_t refVal_setName;
@@ -83,39 +83,39 @@ bool Category::fromJson(const web::json::value& val)
8383
void Category::toMultipart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix) const
8484
{
8585
utility::string_t namePrefix = prefix;
86-
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t(U(".")))
86+
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t(_XPLATSTR(".")))
8787
{
88-
namePrefix += utility::conversions::to_string_t(U("."));
88+
namePrefix += utility::conversions::to_string_t(_XPLATSTR("."));
8989
}
9090
if(m_IdIsSet)
9191
{
92-
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(U("id")), m_Id));
92+
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(_XPLATSTR("id")), m_Id));
9393
}
9494
if(m_NameIsSet)
9595
{
96-
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(U("name")), m_Name));
96+
multipart->add(ModelBase::toHttpContent(namePrefix + utility::conversions::to_string_t(_XPLATSTR("name")), m_Name));
9797
}
9898
}
9999

100100
bool Category::fromMultiPart(std::shared_ptr<MultipartFormData> multipart, const utility::string_t& prefix)
101101
{
102102
bool ok = true;
103103
utility::string_t namePrefix = prefix;
104-
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t(U(".")))
104+
if(namePrefix.size() > 0 && namePrefix.substr(namePrefix.size() - 1) != utility::conversions::to_string_t(_XPLATSTR(".")))
105105
{
106-
namePrefix += utility::conversions::to_string_t(U("."));
106+
namePrefix += utility::conversions::to_string_t(_XPLATSTR("."));
107107
}
108108

109-
if(multipart->hasContent(utility::conversions::to_string_t(U("id"))))
109+
if(multipart->hasContent(utility::conversions::to_string_t(_XPLATSTR("id"))))
110110
{
111111
int64_t refVal_setId;
112-
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t(U("id"))), refVal_setId );
112+
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t(_XPLATSTR("id"))), refVal_setId );
113113
setId(refVal_setId);
114114
}
115-
if(multipart->hasContent(utility::conversions::to_string_t(U("name"))))
115+
if(multipart->hasContent(utility::conversions::to_string_t(_XPLATSTR("name"))))
116116
{
117117
utility::string_t refVal_setName;
118-
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t(U("name"))), refVal_setName );
118+
ok &= ModelBase::fromHttpContent(multipart->getContent(utility::conversions::to_string_t(_XPLATSTR("name"))), refVal_setName );
119119
setName(refVal_setName);
120120
}
121121
return ok;

0 commit comments

Comments
 (0)