Skip to content

Commit be3e33f

Browse files
fvarosewing328
authored andcommitted
[C++] Sanitize operation ids. (#6664)
* [C++] Sanitize operation ids. * [C++] Handle reserved words in `toOperationId`. * [C++] Re-order reserved words alphabetically. * [C++] Add missing reserved words.
1 parent 27850d9 commit be3e33f

File tree

1 file changed

+57
-35
lines changed

1 file changed

+57
-35
lines changed

modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractCppCodegen.java

Lines changed: 57 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,77 +17,90 @@ public AbstractCppCodegen() {
1717
*/
1818
setReservedWordsLowerCase(
1919
Arrays.asList(
20+
"alignas",
21+
"alignof",
22+
"and",
23+
"and_eq",
24+
"asm",
2025
"auto",
26+
"bitand",
27+
"bitor",
28+
"bool",
2129
"break",
2230
"case",
31+
"catch",
2332
"char",
33+
"char16_t",
34+
"char32_t",
35+
"class",
36+
"compl",
37+
"concept",
2438
"const",
39+
"constexpr",
40+
"const_cast",
2541
"continue",
42+
"decltype",
2643
"default",
44+
"delete",
2745
"do",
2846
"double",
47+
"dynamic_cast",
2948
"else",
3049
"enum",
50+
"explicit",
51+
"export",
3152
"extern",
53+
"false",
3254
"float",
3355
"for",
56+
"friend",
3457
"goto",
3558
"if",
59+
"inline",
3660
"int",
3761
"long",
38-
"register",
39-
"return",
40-
"short",
41-
"signed",
42-
"sizeof",
43-
"static",
44-
"struct",
45-
"switch",
46-
"typedef",
47-
"union",
48-
"unsigned",
49-
"void",
50-
"volatile",
51-
"while",
52-
"asm",
53-
"bool",
54-
"catch",
55-
"class",
56-
"const_cast",
57-
"delete",
58-
"dynamic_cast",
59-
"explicit",
60-
"false",
61-
"friend",
62-
"inline",
6362
"mutable",
6463
"namespace",
6564
"new",
65+
"noexcept",
66+
"not",
67+
"not_eq",
68+
"nullptr",
6669
"operator",
70+
"or",
71+
"or_eq",
6772
"private",
68-
"public",
6973
"protected",
74+
"public",
75+
"register",
7076
"reinterpret_cast",
77+
"requires",
78+
"return",
79+
"short",
80+
"signed",
81+
"sizeof",
82+
"static",
83+
"static_assert",
7184
"static_cast",
85+
"struct",
86+
"switch",
7287
"template",
7388
"this",
89+
"thread_local",
7490
"throw",
7591
"true",
7692
"try",
93+
"typedef",
7794
"typeid",
7895
"typename",
96+
"union",
97+
"unsigned",
7998
"using",
8099
"virtual",
100+
"void",
101+
"volatile",
81102
"wchar_t",
82-
"and",
83-
"and_eq",
84-
"bitand",
85-
"bitor",
86-
"compl",
87-
"not",
88-
"not_eq",
89-
"or",
90-
"or_eq",
103+
"while",
91104
"xor",
92105
"xor_eq")
93106
);
@@ -127,6 +140,15 @@ public String escapeReservedWord(String name) {
127140
return sanitizeName("_" + name);
128141
}
129142

143+
@Override
144+
public String toOperationId(String operationId) {
145+
if (isReservedWord(operationId)) {
146+
LOGGER.warn(operationId + " (reserved word) cannot be used as method name. Renamed to " + escapeReservedWord(operationId));
147+
return escapeReservedWord(operationId);
148+
}
149+
return sanitizeName(super.toOperationId(operationId));
150+
}
151+
130152
@Override
131153
public String toParamName(String name) {
132154
return sanitizeName(super.toParamName(name));

0 commit comments

Comments
 (0)