112
112
import static io .micronaut .openapi .generator .Utils .calcQueryValueFormat ;
113
113
import static io .micronaut .openapi .generator .Utils .isDateType ;
114
114
import static io .micronaut .openapi .generator .Utils .normalizeExtraAnnotations ;
115
+ import static io .micronaut .openapi .generator .Utils .normalizeStr ;
116
+ import static io .micronaut .openapi .generator .Utils .normalizeStrValue ;
115
117
import static io .micronaut .openapi .generator .Utils .processDuplicateVars ;
116
118
import static io .micronaut .openapi .generator .Utils .processGenericAnnotations ;
117
119
import static io .micronaut .openapi .generator .Utils .readListOfStringsProperty ;
@@ -995,6 +997,7 @@ public void addOperationToGroup(String tag, String resourcePath, Operation opera
995
997
List <CodegenOperation > opList = operations .computeIfAbsent (basePath , k -> new ArrayList <>());
996
998
opList .add (co );
997
999
co .baseName = basePath ;
1000
+ co .vendorExtensions .put ("normalizedBaseName" , normalizeStr (basePath ));
998
1001
return ;
999
1002
}
1000
1003
@@ -1004,6 +1007,12 @@ public void addOperationToGroup(String tag, String resourcePath, Operation opera
1004
1007
}
1005
1008
1006
1009
super .addOperationToGroup (superSanitizeTag (tag ), resourcePath , operation , co , operations );
1010
+
1011
+ var foundTag = co .tags .stream ().filter (t -> t .getName ().equals (tag )).findFirst ().orElse (null );
1012
+ co .vendorExtensions .put ("normalizedBaseTag" , normalizeStr (tag ));
1013
+ if (foundTag != null ) {
1014
+ co .vendorExtensions .put ("normalizedTagDesc" , normalizeStr (foundTag .getDescription ()));
1015
+ }
1007
1016
}
1008
1017
1009
1018
@ Override
@@ -1121,6 +1130,9 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
1121
1130
1122
1131
for (CodegenOperation op : operationList ) {
1123
1132
1133
+ objs .put ("normalizedBaseTag" , op .vendorExtensions .get ("normalizedBaseTag" ));
1134
+ objs .put ("normalizedTagDesc" , op .vendorExtensions .get ("normalizedTagDesc" ));
1135
+
1124
1136
handleImplicitHeaders (op );
1125
1137
handleConstantParams (op );
1126
1138
@@ -1199,6 +1211,7 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
1199
1211
param .isBodyParam = true ;
1200
1212
param .isFormParam = false ;
1201
1213
param .vendorExtensions .put ("isPart" , true );
1214
+ param .vendorExtensions .put ("baseNameNormalized" , normalizeStr (param .baseName ));
1202
1215
if (param .isEnumRef ) {
1203
1216
param .isEnum = true ;
1204
1217
}
@@ -1211,6 +1224,7 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
1211
1224
p .isBodyParam = true ;
1212
1225
p .isFormParam = false ;
1213
1226
p .vendorExtensions .put ("isPart" , true );
1227
+ p .vendorExtensions .put ("baseNameNormalized" , normalizeStr (p .baseName ));
1214
1228
if (p .isEnumRef ) {
1215
1229
p .isEnum = true ;
1216
1230
}
@@ -1226,7 +1240,7 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
1226
1240
param .isEnum = true ;
1227
1241
}
1228
1242
processGenericAnnotations (param , useBeanValidation , false , param .isNullable || !param .required ,
1229
- param .required , false , true , ksp );
1243
+ param .required , false , true , true , ksp );
1230
1244
param .vendorExtensions .put ("isString" , "string" .equalsIgnoreCase (param .dataType ));
1231
1245
param .vendorExtensions .put ("withoutExample" , param .example == null || param .example .equals (NULL_STRING ));
1232
1246
if (useBeanValidation && ((!param .isContainer && param .isModel )
@@ -1237,7 +1251,7 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
1237
1251
// check pattern property for date types: if set, need use this pattern as `@Format` annotation value
1238
1252
if (isDateType (param .dataType )) {
1239
1253
if (StringUtils .isNotEmpty (param .pattern )) {
1240
- param .vendorExtensions .put ("formatPattern" , param .pattern );
1254
+ param .vendorExtensions .put ("formatPattern" , normalizeStr ( param .pattern ) );
1241
1255
param .pattern = null ;
1242
1256
}
1243
1257
param .minItems = null ;
@@ -1262,9 +1276,11 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
1262
1276
additionalProperties .put ("enumParams" , enumParams );
1263
1277
1264
1278
if (op .returnProperty != null ) {
1265
- processGenericAnnotations (op .returnProperty , useBeanValidation , false , false , false , false , false , ksp );
1279
+ processGenericAnnotations (op .returnProperty , useBeanValidation , false , false , false , false , false , true , ksp );
1266
1280
op .returnType = op .returnProperty .vendorExtensions .get ("typeWithEnumWithGenericAnnotations" ).toString ();
1267
1281
}
1282
+
1283
+ normalizeTextsInOperation (op );
1268
1284
}
1269
1285
1270
1286
if (needToAddImportFormat ) {
@@ -1274,6 +1290,80 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List<Mo
1274
1290
return objs ;
1275
1291
}
1276
1292
1293
+ private void normalizeTextsInOperation (CodegenOperation op ) {
1294
+
1295
+ if (op .vendorExtensions .containsKey ("x-deprecated-message" )) {
1296
+ op .vendorExtensions .put ("x-deprecated-message-normalized" , normalizeStr (op .vendorExtensions .get ("x-deprecated-message" ).toString ()));
1297
+ }
1298
+
1299
+ if (op .vendorExtensions .containsKey ("x-roles" )) {
1300
+ var roles = (List <String >) op .vendorExtensions .get ("x-roles" );
1301
+ var normalizedRoles = new ArrayList <String >(roles .size ());
1302
+ for (var role : roles ) {
1303
+ normalizedRoles .add (normalizeStr (role ));
1304
+ }
1305
+ op .vendorExtensions .put ("x-roles-normalized" , normalizedRoles );
1306
+ }
1307
+
1308
+ if (op .summary != null ) {
1309
+ op .vendorExtensions .put ("summaryNormalized" , normalizeStr (op .summary ));
1310
+ }
1311
+ if (op .notes != null ) {
1312
+ op .vendorExtensions .put ("notesNormalized" , normalizeStr (op .notes ));
1313
+ }
1314
+ if (op .tags != null ) {
1315
+ for (var tag : op .tags ) {
1316
+ tag .setName (normalizeStr (tag .getName ()));
1317
+ }
1318
+ }
1319
+ if (op .responses != null ) {
1320
+ for (var response : op .responses ) {
1321
+ response .vendorExtensions .put ("messageNormalized" , normalizeStr (response .message ));
1322
+ }
1323
+ }
1324
+ if (op .produces != null ) {
1325
+ for (var produce : op .produces ) {
1326
+ produce .put ("mediaTypeNormalized" , normalizeStr (produce .get ("mediaType" )));
1327
+ }
1328
+ }
1329
+ if (op .consumes != null ) {
1330
+ for (var consume : op .consumes ) {
1331
+ consume .put ("mediaTypeNormalized" , normalizeStr (consume .get ("mediaType" )));
1332
+ }
1333
+ }
1334
+ if (op .vendorExtensions .containsKey ("swaggerParams" )) {
1335
+ for (var swaggerParam : (List <CodegenParameter >) op .vendorExtensions .get ("swaggerParams" )) {
1336
+ swaggerParam .vendorExtensions .put ("baseNameNormalized" , normalizeStr (swaggerParam .baseName ));
1337
+ swaggerParam .vendorExtensions .put ("descriptionNormalized" , normalizeStr (swaggerParam .description ));
1338
+ }
1339
+ }
1340
+ if (op .authMethods != null ) {
1341
+ for (var authMethod : op .authMethods ) {
1342
+ authMethod .vendorExtensions .put ("nameNormalized" , normalizeStr (authMethod .name ));
1343
+ if (authMethod .scopes != null ) {
1344
+ for (var scope : authMethod .scopes ) {
1345
+ scope .put ("scopeNormalized" , normalizeStr ((String ) scope .get ("scope" )));
1346
+ }
1347
+ }
1348
+ }
1349
+ }
1350
+ op .vendorExtensions .put ("pathNormalized" , normalizeStr (op .path ));
1351
+
1352
+ if (op .allParams != null ) {
1353
+ for (var param : op .allParams ) {
1354
+ param .vendorExtensions .put ("baseNameNormalized" , normalizeStr (param .baseName ));
1355
+ if (param .defaultValue != null ) {
1356
+ param .vendorExtensions .put ("defaultValueNormalized" , normalizeStr (param .defaultValue ));
1357
+ }
1358
+ normalizeStrValue ("x-pattern-message" , param .vendorExtensions );
1359
+ normalizeStrValue ("x-size-message" , param .vendorExtensions );
1360
+ normalizeStrValue ("x-not-null-message" , param .vendorExtensions );
1361
+ normalizeStrValue ("x-minimum-message" , param .vendorExtensions );
1362
+ normalizeStrValue ("x-maximum-message" , param .vendorExtensions );
1363
+ }
1364
+ }
1365
+ }
1366
+
1277
1367
/**
1278
1368
* This method removes all implicit header parameters from the list of parameters.
1279
1369
*
@@ -1727,7 +1817,7 @@ public CodegenParameter fromParameter(Parameter p, Set<String> imports) {
1727
1817
if (realName .contains ("`" )) {
1728
1818
realName = realName .replace ("`" , "" );
1729
1819
}
1730
- parameter .vendorExtensions .put ("realName" , realName );
1820
+ parameter .vendorExtensions .put ("realName" , normalizeStr ( realName ) );
1731
1821
1732
1822
Schema parameterSchema ;
1733
1823
if (p .getSchema () != null ) {
@@ -1766,7 +1856,7 @@ public CodegenParameter fromParameter(Parameter p, Set<String> imports) {
1766
1856
if (ksp && !defaultValueInit .equals (NULL_STRING )) {
1767
1857
parameter .isNullable = false ;
1768
1858
}
1769
- parameter .vendorExtensions .put ("defaultValueInit" , defaultValueInit );
1859
+ parameter .vendorExtensions .put ("defaultValueInit" , normalizeStr ( defaultValueInit ) );
1770
1860
parameter .vendorExtensions .put ("defaultValueIsNotNull" , !defaultValueInit .equals (NULL_STRING ));
1771
1861
}
1772
1862
@@ -1806,7 +1896,7 @@ public CodegenProperty fromProperty(String name, Schema schema, boolean required
1806
1896
property .nameInCamelCase = camelize (realName , LOWERCASE_FIRST_LETTER );
1807
1897
property .nameInSnakeCase = CaseFormat .UPPER_CAMEL .to (CaseFormat .UPPER_UNDERSCORE , property .nameInCamelCase );
1808
1898
}
1809
- property .vendorExtensions .put ("realName" , realName );
1899
+ property .vendorExtensions .put ("realName" , normalizeStr ( realName ) );
1810
1900
1811
1901
if (schema != null && schema .get$ref () != null ) {
1812
1902
var refSchema = ModelUtils .getSchemaFromRefToSchemaWithProperties (openAPI , schema .get$ref ());
@@ -1838,7 +1928,7 @@ public CodegenProperty fromProperty(String name, Schema schema, boolean required
1838
1928
defaultValueInit = NULL_STRING ;
1839
1929
}
1840
1930
if (defaultValueInit != null ) {
1841
- property .vendorExtensions .put ("defaultValueInit" , defaultValueInit );
1931
+ property .vendorExtensions .put ("defaultValueInit" , normalizeStr ( defaultValueInit ) );
1842
1932
}
1843
1933
1844
1934
return property ;
@@ -2173,6 +2263,10 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
2173
2263
model .vendorExtensions .put ("requiredParentVarsWithoutDiscriminator" , requiredParentVarsWithoutDiscriminator );
2174
2264
}
2175
2265
2266
+ if (model .vendorExtensions .containsKey ("x-deprecated-message" )) {
2267
+ model .vendorExtensions .put ("x-deprecated-message-normalized" , normalizeStr ((String ) model .vendorExtensions .get ("x-deprecated-message" )));
2268
+ }
2269
+ model .vendorExtensions .put ("descriptionNormalized" , normalizeStr (model .description ));
2176
2270
model .vendorExtensions .put ("requiredVarsWithoutDiscriminator" , requiredVarsWithoutDiscriminator );
2177
2271
model .vendorExtensions .put ("requiredVars" , requiredVars );
2178
2272
model .vendorExtensions .put ("withRequiredOrOptionalVars" , !requiredVarsWithoutDiscriminator .isEmpty () || !optionalVars .isEmpty ());
@@ -2340,10 +2434,11 @@ protected void updateEnumVarsWithExtensions(List<Map<String, Object>> enumVars,
2340
2434
2341
2435
var baseType = (String ) vendorExtensions .get ("baseType" );
2342
2436
for (var enumVar : enumVars ) {
2437
+ var value = (String ) enumVar .get ("value" );
2343
2438
if ((boolean ) enumVar .get ("isString" )) {
2439
+ enumVar .put ("valueNormalized" , normalizeStr (value ));
2344
2440
continue ;
2345
2441
}
2346
- var value = (String ) enumVar .get ("value" );
2347
2442
value = value .replace ("\" " , "" );
2348
2443
if ("char" .equals (baseType ) && !value .startsWith ("'" )) {
2349
2444
enumVar .put ("value" , "'" + value + "'" );
@@ -2352,6 +2447,7 @@ protected void updateEnumVarsWithExtensions(List<Map<String, Object>> enumVars,
2352
2447
} else if ("byte" .equalsIgnoreCase (baseType )) {
2353
2448
enumVar .put ("value" , value );
2354
2449
}
2450
+ enumVar .put ("valueNormalized" , enumVar .get ("value" ));
2355
2451
}
2356
2452
}
2357
2453
@@ -2459,6 +2555,22 @@ private void processOneOfModels(CodegenModel model, Collection<ModelsMap> models
2459
2555
2460
2556
private void processProperty (CodegenProperty property , boolean isServer , CodegenModel model , Map <String , ModelsMap > models ) {
2461
2557
2558
+ property .vendorExtensions .put ("baseNameNormalized" , normalizeStr (property .baseName ));
2559
+ if (property .example != null ) {
2560
+ property .vendorExtensions .put ("exampleNormalized" , normalizeStr (property .example ));
2561
+ }
2562
+ if (property .description != null ) {
2563
+ property .vendorExtensions .put ("descriptionNormalized" , normalizeStr (property .description ));
2564
+ }
2565
+ if (property .vendorExtensions .containsKey ("x-deprecated-message" )) {
2566
+ property .vendorExtensions .put ("x-deprecated-message-normalized" , normalizeStr ((String ) property .vendorExtensions .get ("x-deprecated-message" )));
2567
+ }
2568
+ normalizeStrValue ("x-pattern-message" , property .vendorExtensions );
2569
+ normalizeStrValue ("x-size-message" , property .vendorExtensions );
2570
+ normalizeStrValue ("x-not-null-message" , property .vendorExtensions );
2571
+ normalizeStrValue ("x-minimum-message" , property .vendorExtensions );
2572
+ normalizeStrValue ("x-maximum-message" , property .vendorExtensions );
2573
+
2462
2574
property .vendorExtensions .put ("withRequiredAndOptionalVars" , model .vendorExtensions .get ("withRequiredAndOptionalVars" ));
2463
2575
property .vendorExtensions .put ("inRequiredArgsConstructor" , !property .isReadOnly || isServer );
2464
2576
property .vendorExtensions .put ("isServer" , isServer );
@@ -2469,6 +2581,7 @@ private void processProperty(CodegenProperty property, boolean isServer, Codegen
2469
2581
property .vendorExtensions .put ("x-implements" , model .vendorExtensions .get ("x-implements" ));
2470
2582
if (NULL_STRING .equals (property .example )) {
2471
2583
property .example = null ;
2584
+ property .vendorExtensions .remove ("exampleNormalized" );
2472
2585
}
2473
2586
if (useBeanValidation && (
2474
2587
(!property .isContainer && property .isModel )
@@ -2480,7 +2593,7 @@ private void processProperty(CodegenProperty property, boolean isServer, Codegen
2480
2593
// check pattern property for date types: if set, need use this pattern as `@Format` annotation value
2481
2594
if (isDateType (property .dataType )) {
2482
2595
if (StringUtils .isNotEmpty (property .pattern )) {
2483
- property .vendorExtensions .put ("formatPattern" , property .pattern );
2596
+ property .vendorExtensions .put ("formatPattern" , normalizeStr ( property .pattern ) );
2484
2597
property .pattern = null ;
2485
2598
}
2486
2599
property .minItems = null ;
@@ -2494,7 +2607,7 @@ private void processProperty(CodegenProperty property, boolean isServer, Codegen
2494
2607
}
2495
2608
2496
2609
processGenericAnnotations (property , useBeanValidation , false , property .isNullable || property .isDiscriminator ,
2497
- property .required , property .isReadOnly , true , ksp );
2610
+ property .required , property .isReadOnly , true , true , ksp );
2498
2611
2499
2612
normalizeExtraAnnotations (EXT_ANNOTATIONS_FIELD , true , property .vendorExtensions );
2500
2613
normalizeExtraAnnotations (EXT_ANNOTATIONS_SETTER , true , property .vendorExtensions );
0 commit comments