@@ -121,7 +121,7 @@ public Map<String, Object> postProcessModels(Map<String, Object> objs) {
121
121
return objs ;
122
122
}
123
123
124
-
124
+
125
125
// override with any special post-processing
126
126
@ SuppressWarnings ("static-method" )
127
127
public Map <String , Object > postProcessOperations (Map <String , Object > objs ) {
@@ -157,7 +157,7 @@ public void processSwagger(Swagger swagger) {
157
157
// override with any special text escaping logic
158
158
@ SuppressWarnings ("static-method" )
159
159
public String escapeText (String input ) {
160
- if (input != null ) {
160
+ if (input != null ) {
161
161
input = input .trim (); // FIXME: a parameter should not be assigned. Also declare the methods parameters as 'final'.
162
162
String output = input .replaceAll ("\n " , "\\ \\ n" );
163
163
output = output .replace ("\r " , "\\ r" );
@@ -258,7 +258,7 @@ public Map<String, Object> additionalProperties() {
258
258
public Map <String , Object > vendorExtensions () {
259
259
return vendorExtensions ;
260
260
}
261
-
261
+
262
262
public List <SupportingFile > supportingFiles () {
263
263
return supportingFiles ;
264
264
}
@@ -297,7 +297,7 @@ public void setEnsureUniqueParams(Boolean ensureUniqueParams) {
297
297
298
298
/**
299
299
* Return the file name of the Api Test
300
- *
300
+ *
301
301
* @param name the file name of the Api
302
302
* @return the file name of the Api
303
303
*/
@@ -307,7 +307,7 @@ public String toApiFilename(String name) {
307
307
308
308
/**
309
309
* Return the file name of the Api Test
310
- *
310
+ *
311
311
* @param name the file name of the Api
312
312
* @return the file name of the Api
313
313
*/
@@ -317,7 +317,7 @@ public String toApiTestFilename(String name) {
317
317
318
318
/**
319
319
* Return the variable name in the Api
320
- *
320
+ *
321
321
* @param name the varible name of the Api
322
322
* @return the snake-cased variable name
323
323
*/
@@ -327,7 +327,7 @@ public String toApiVarName(String name) {
327
327
328
328
/**
329
329
* Return the capitalized file name of the model test
330
- *
330
+ *
331
331
* @param name the model name
332
332
* @return the file name of the model
333
333
*/
@@ -337,17 +337,17 @@ public String toModelFilename(String name) {
337
337
338
338
/**
339
339
* Return the capitalized file name of the model test
340
- *
340
+ *
341
341
* @param name the model name
342
342
* @return the file name of the model
343
343
*/
344
344
public String toModelTestFilename (String name ) {
345
345
return initialCaps (name ) + "Test" ;
346
346
}
347
-
347
+
348
348
/**
349
349
* Return the operation ID (method name)
350
- *
350
+ *
351
351
* @param operationId operation ID
352
352
* @return the sanitized method name
353
353
*/
@@ -364,7 +364,7 @@ public String toOperationId(String operationId) {
364
364
/**
365
365
* Return the variable name by removing invalid characters and proper escaping if
366
366
* it's a reserved word.
367
- *
367
+ *
368
368
* @param name the variable name
369
369
* @return the sanitized variable name
370
370
*/
@@ -379,7 +379,7 @@ public String toVarName(String name) {
379
379
/**
380
380
* Return the parameter name by removing invalid characters and proper escaping if
381
381
* it's a reserved word.
382
- *
382
+ *
383
383
* @param name Codegen property object
384
384
* @return the sanitized parameter name
385
385
*/
@@ -393,18 +393,18 @@ public String toParamName(String name) {
393
393
394
394
/**
395
395
* Return the Enum name (e.g. StatusEnum given 'status')
396
- *
396
+ *
397
397
* @param property Codegen property object
398
398
* @return the Enum name
399
399
*/
400
400
@ SuppressWarnings ("static-method" )
401
401
public String toEnumName (CodegenProperty property ) {
402
402
return StringUtils .capitalize (property .name ) + "Enum" ;
403
403
}
404
-
404
+
405
405
/**
406
406
* Return the escaped name of the reserved word
407
- *
407
+ *
408
408
* @param name the name to be escaped
409
409
* @return the escaped reserved word
410
410
*
@@ -417,7 +417,7 @@ public String escapeReservedWord(String name) {
417
417
418
418
/**
419
419
* Return the fully-qualified "Model" name for import
420
- *
420
+ *
421
421
* @param name the name of the "Model"
422
422
* @return the fully-qualified "Model" name for import
423
423
*/
@@ -431,7 +431,7 @@ public String toModelImport(String name) {
431
431
432
432
/**
433
433
* Return the fully-qualified "Api" name for import
434
- *
434
+ *
435
435
* @param name the name of the "Api"
436
436
* @return the fully-qualified "Api" name for import
437
437
*/
@@ -442,7 +442,7 @@ public String toApiImport(String name) {
442
442
/**
443
443
* Default constructor.
444
444
* This method will map between Swagger type and language-specified type, as well as mapping
445
- * between Swagger type and the corresponding import statement for the language. This will
445
+ * between Swagger type and the corresponding import statement for the language. This will
446
446
* also add some language specified CLI options, if any.
447
447
*
448
448
*
@@ -603,7 +603,7 @@ public String toInstantiationType(Property p) {
603
603
* @param p Swagger property object
604
604
* @return string presentation of the example value of the property
605
605
*/
606
- @ SuppressWarnings ("static-method" )
606
+ @ SuppressWarnings ("static-method" )
607
607
public String toExampleValue (Property p ) {
608
608
if (p .getExample () != null ) {
609
609
return p .getExample ().toString ();
@@ -689,7 +689,7 @@ public String toDefaultValue(Property p) {
689
689
return "null" ;
690
690
}
691
691
}
692
-
692
+
693
693
/**
694
694
* Return the property initialized from a data object
695
695
* Useful for initialization with a plain object in Javascript
@@ -965,7 +965,7 @@ public String getterAndSetterCapitalize(String name) {
965
965
return camelize (toVarName (name ));
966
966
967
967
}
968
-
968
+
969
969
/**
970
970
* Convert Swagger Property object to Codegen Property object
971
971
*
@@ -1032,7 +1032,7 @@ public CodegenProperty fromProperty(String name, Property p) {
1032
1032
property .allowableValues = allowableValues ;
1033
1033
}
1034
1034
}
1035
-
1035
+
1036
1036
if (p instanceof IntegerProperty ) {
1037
1037
IntegerProperty sp = (IntegerProperty ) p ;
1038
1038
property .isInteger = true ;
@@ -1050,7 +1050,7 @@ public CodegenProperty fromProperty(String name, Property p) {
1050
1050
property .allowableValues = allowableValues ;
1051
1051
}
1052
1052
}
1053
-
1053
+
1054
1054
if (p instanceof LongProperty ) {
1055
1055
LongProperty sp = (LongProperty ) p ;
1056
1056
property .isLong = true ;
@@ -1068,7 +1068,7 @@ public CodegenProperty fromProperty(String name, Property p) {
1068
1068
property .allowableValues = allowableValues ;
1069
1069
}
1070
1070
}
1071
-
1071
+
1072
1072
if (p instanceof BooleanProperty ) {
1073
1073
property .isBoolean = true ;
1074
1074
}
@@ -1098,7 +1098,7 @@ public CodegenProperty fromProperty(String name, Property p) {
1098
1098
property .allowableValues = allowableValues ;
1099
1099
}
1100
1100
}
1101
-
1101
+
1102
1102
if (p instanceof FloatProperty ) {
1103
1103
FloatProperty sp = (FloatProperty ) p ;
1104
1104
property .isFloat = true ;
@@ -1116,7 +1116,7 @@ public CodegenProperty fromProperty(String name, Property p) {
1116
1116
property .allowableValues = allowableValues ;
1117
1117
}
1118
1118
}
1119
-
1119
+
1120
1120
if (p instanceof DateProperty ) {
1121
1121
DateProperty sp = (DateProperty ) p ;
1122
1122
property .isDate = true ;
@@ -1134,7 +1134,7 @@ public CodegenProperty fromProperty(String name, Property p) {
1134
1134
property .allowableValues = allowableValues ;
1135
1135
}
1136
1136
}
1137
-
1137
+
1138
1138
if (p instanceof DateTimeProperty ) {
1139
1139
DateTimeProperty sp = (DateTimeProperty ) p ;
1140
1140
property .isDateTime = true ;
@@ -1229,7 +1229,7 @@ private static Response findMethodResponse(Map<String, Response> responses) {
1229
1229
}
1230
1230
return responses .get (code );
1231
1231
}
1232
-
1232
+
1233
1233
/**
1234
1234
* Convert Swagger Operation object to Codegen Operation object (without providing a Swagger object)
1235
1235
*
@@ -1242,7 +1242,7 @@ private static Response findMethodResponse(Map<String, Response> responses) {
1242
1242
public CodegenOperation fromOperation (String path , String httpMethod , Operation operation , Map <String , Model > definitions ) {
1243
1243
return fromOperation (path , httpMethod , operation , definitions , null );
1244
1244
}
1245
-
1245
+
1246
1246
/**
1247
1247
* Convert Swagger Operation object to Codegen Operation object
1248
1248
*
@@ -1277,11 +1277,11 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
1277
1277
// empty list, do nothing to override global setting
1278
1278
}
1279
1279
} else if (swagger != null && swagger .getConsumes () != null && swagger .getConsumes ().size () > 0 ) {
1280
- // use consumes defined globally
1280
+ // use consumes defined globally
1281
1281
consumes = swagger .getConsumes ();
1282
1282
LOGGER .debug ("No consumes defined in operation. Using global consumes (" + swagger .getConsumes () + ") for " + op .operationId );
1283
1283
}
1284
-
1284
+
1285
1285
// if "consumes" is defined (per operation or using global definition)
1286
1286
if (consumes != null && consumes .size () > 0 ) {
1287
1287
List <Map <String , String >> c = new ArrayList <Map <String , String >>();
@@ -1310,11 +1310,11 @@ public CodegenOperation fromOperation(String path, String httpMethod, Operation
1310
1310
// empty list, do nothing to override global setting
1311
1311
}
1312
1312
} else if (swagger != null && swagger .getProduces () != null && swagger .getProduces ().size () > 0 ) {
1313
- // use produces defined globally
1313
+ // use produces defined globally
1314
1314
produces = swagger .getProduces ();
1315
1315
LOGGER .debug ("No produces defined in operation. Using global produces (" + swagger .getProduces () + ") for " + op .operationId );
1316
1316
}
1317
-
1317
+
1318
1318
// if "produces" is defined (per operation or using global definition)
1319
1319
if (produces != null && produces .size () > 0 ) {
1320
1320
List <Map <String , String >> c = new ArrayList <Map <String , String >>();
@@ -1556,7 +1556,7 @@ public CodegenResponse fromResponse(String responseCode, Response response) {
1556
1556
}
1557
1557
return r ;
1558
1558
}
1559
-
1559
+
1560
1560
/**
1561
1561
* Convert Swagger Parameter object to Codegen Parameter object
1562
1562
*
@@ -1658,7 +1658,7 @@ public CodegenParameter fromParameter(Parameter param, Set<String> imports) {
1658
1658
p .maxLength = qp .getMaxLength ();
1659
1659
p .minLength = qp .getMinLength ();
1660
1660
p .pattern = qp .getPattern ();
1661
-
1661
+
1662
1662
p .maximum = qp .getMaximum ();
1663
1663
p .exclusiveMaximum = qp .isExclusiveMaximum ();
1664
1664
p .minimum = qp .getMinimum ();
@@ -1783,14 +1783,14 @@ public List<CodegenSecurity> fromSecurity(Map<String, SecuritySchemeDefinition>
1783
1783
Map <String , Object > scope = new HashMap <String , Object >();
1784
1784
scope .put ("scope" , scopeEntry .getKey ());
1785
1785
scope .put ("description" , scopeEntry .getValue ());
1786
-
1786
+
1787
1787
count += 1 ;
1788
1788
if (count < numScopes ) {
1789
1789
scope .put ("hasMore" , "true" );
1790
1790
} else {
1791
1791
scope .put ("hasMore" , null );
1792
1792
}
1793
-
1793
+
1794
1794
scopes .add (scope );
1795
1795
}
1796
1796
sec .scopes = scopes ;
@@ -1803,6 +1803,17 @@ public List<CodegenSecurity> fromSecurity(Map<String, SecuritySchemeDefinition>
1803
1803
return secs ;
1804
1804
}
1805
1805
1806
+ protected void setReservedWordsLowerCase (List <String > words ) {
1807
+ reservedWords = new HashSet <String >();
1808
+ for (String word : words ) {
1809
+ reservedWords .add (word .toLowerCase ());
1810
+ }
1811
+ }
1812
+
1813
+ protected boolean isReservedWord (String word ) {
1814
+ return word != null && reservedWords .contains (word .toLowerCase ());
1815
+ }
1816
+
1806
1817
/**
1807
1818
* Get operationId from the operation object, and if it's blank, generate a new one from the given parameters.
1808
1819
*
@@ -2046,9 +2057,9 @@ private void addVars(CodegenModel m, Map<String, Property> properties, Collectio
2046
2057
m .vars .add (cp );
2047
2058
}
2048
2059
}
2049
-
2060
+
2050
2061
m .mandatory = mandatory ;
2051
-
2062
+
2052
2063
} else {
2053
2064
m .emptyVars = true ;
2054
2065
m .hasVars = false ;
@@ -2077,7 +2088,7 @@ public String apply(String input) {
2077
2088
}
2078
2089
return name ;
2079
2090
}
2080
-
2091
+
2081
2092
/**
2082
2093
* Camelize name (parameter, property, method, etc) with upper case for first letter
2083
2094
* copied from Twitter elephant bird
@@ -2221,7 +2232,7 @@ public String sanitizeName(String name) {
2221
2232
// character with _ or empty character. Below aims to spell out different cases we've
2222
2233
// encountered so far and hopefully make it easier for others to add more special
2223
2234
// cases in the future.
2224
-
2235
+
2225
2236
// better error handling when map/array type is invalid
2226
2237
if (name == null ) {
2227
2238
LOGGER .error ("String to be sanitized is null. Default to ERROR_UNKNOWN" );
0 commit comments