@@ -156,8 +156,8 @@ public AbstractCppCodegen() {
156156 RESERVED_WORD_PREFIX_DESC ,
157157 this .reservedWordPrefix );
158158 addOption (VARIABLE_NAME_FIRST_CHARACTER_UPPERCASE_OPTION ,
159- VARIABLE_NAME_FIRST_CHARACTER_UPPERCASE_DESC ,
160- Boolean .toString (this .variableNameFirstCharacterUppercase ));
159+ VARIABLE_NAME_FIRST_CHARACTER_UPPERCASE_DESC ,
160+ Boolean .toString (this .variableNameFirstCharacterUppercase ));
161161 }
162162
163163 @ Override
@@ -185,18 +185,23 @@ public String toApiName(String type) {
185185 }
186186
187187 @ Override
188- public String toModelName (String type ) {
189- if (type == null ) {
188+ public String toModelName (String name ) {
189+ // obtain the name from modelNameMapping directly if provided
190+ if (modelNameMapping .containsKey (name )) {
191+ return modelNameMapping .get (name );
192+ }
193+
194+ if (name == null ) {
190195 LOGGER .warn ("Model name can't be null. Default to 'UnknownModel'." );
191- type = "UnknownModel" ;
196+ name = "UnknownModel" ;
192197 }
193198
194- if (typeMapping .keySet ().contains (type ) || typeMapping .values ().contains (type )
195- || importMapping .values ().contains (type ) || defaultIncludes .contains (type )
196- || languageSpecificPrimitives .contains (type )) {
197- return type ;
199+ if (typeMapping .keySet ().contains (name ) || typeMapping .values ().contains (name )
200+ || importMapping .values ().contains (name ) || defaultIncludes .contains (name )
201+ || languageSpecificPrimitives .contains (name )) {
202+ return name ;
198203 } else {
199- String sanitizedName = sanitizeName (modelNamePrefix + Character .toUpperCase (type .charAt (0 )) + type .substring (1 ));
204+ String sanitizedName = sanitizeName (modelNamePrefix + Character .toUpperCase (name .charAt (0 )) + name .substring (1 ));
200205 sanitizedName = sanitizedName .replaceFirst ("^([^_a-zA-Z])" , reservedWordPrefix + "$1" );
201206 return sanitizedName ;
202207 }
@@ -209,6 +214,11 @@ public String toEnumValue(String value, String datatype) {
209214
210215 @ Override
211216 public String toVarName (String name ) {
217+ // obtain the name from nameMapping directly if provided
218+ if (nameMapping .containsKey (name )) {
219+ return nameMapping .get (name );
220+ }
221+
212222 if (typeMapping .keySet ().contains (name ) || typeMapping .values ().contains (name )
213223 || importMapping .values ().contains (name ) || defaultIncludes .contains (name )
214224 || languageSpecificPrimitives .contains (name )) {
@@ -252,6 +262,11 @@ public String toOperationId(String operationId) {
252262
253263 @ Override
254264 public String toParamName (String name ) {
265+ // obtain the name from parameterNameMapping directly if provided
266+ if (parameterNameMapping .containsKey (name )) {
267+ return parameterNameMapping .get (name );
268+ }
269+
255270 if (isReservedWord (name ) || name .matches ("^\\ d.*" )) {
256271 return escapeReservedWord (name );
257272 }
@@ -373,15 +388,15 @@ public void preprocessOpenAPI(OpenAPI openAPI) {
373388 s .url = server .getUrl ();
374389 s .variables = new ArrayList <CodegenServerVariable >();
375390 ServerVariables serverVars = server .getVariables ();
376- if (serverVars != null ){
377- serverVars .forEach ((key ,value ) -> {
378- CodegenServerVariable codegenServerVar = new CodegenServerVariable ();
379- ServerVariable ServerVar = value ;
380- codegenServerVar .name = key ;
381- codegenServerVar .description = ServerVar .getDescription ();
382- codegenServerVar .defaultValue = ServerVar .getDefault ();
383- codegenServerVar .enumValues = ServerVar .getEnum ();
384- s .variables .add (codegenServerVar );
391+ if (serverVars != null ) {
392+ serverVars .forEach ((key , value ) -> {
393+ CodegenServerVariable codegenServerVar = new CodegenServerVariable ();
394+ ServerVariable ServerVar = value ;
395+ codegenServerVar .name = key ;
396+ codegenServerVar .description = ServerVar .getDescription ();
397+ codegenServerVar .defaultValue = ServerVar .getDefault ();
398+ codegenServerVar .enumValues = ServerVar .getEnum ();
399+ s .variables .add (codegenServerVar );
385400 });
386401 }
387402 CodegenServerList .add (s );
@@ -395,15 +410,15 @@ public ModelsMap postProcessModels(ModelsMap objs) {
395410 for (ModelMap mo : objs .getModels ()) {
396411 CodegenModel cm = mo .getModel ();
397412 // cannot handle inheritance from maps and arrays in C++
398- if ((cm .isArray || cm .isMap ) && (cm .parentModel == null )) {
413+ if ((cm .isArray || cm .isMap ) && (cm .parentModel == null )) {
399414 cm .parent = null ;
400415 }
401416 }
402417 return postProcessModelsEnum (objs );
403418 }
404419
405420 @ Override
406- public Map <String , ModelsMap > postProcessAllModels (Map <String , ModelsMap > objs ){
421+ public Map <String , ModelsMap > postProcessAllModels (Map <String , ModelsMap > objs ) {
407422 Map <String , ModelsMap > models = super .postProcessAllModels (objs );
408423 for (final String key : models .keySet ()) {
409424 CodegenModel mo = ModelUtils .getModelByName (key , models );
@@ -414,33 +429,35 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs){
414429
415430 private void addForwardDeclarations (CodegenModel parentModel , Map <String , ModelsMap > objs ) {
416431 List <String > forwardDeclarations = new ArrayList <>();
417- if (!parentModel .hasVars ) {
432+ if (!parentModel .hasVars ) {
418433 return ;
419434 }
420- for (CodegenProperty property : parentModel .vars ){
421- if (!( (property .isContainer && property .mostInnerItems .isModel ) || (property .isModel ) ) ) {
435+ for (CodegenProperty property : parentModel .vars ) {
436+ if (!((property .isContainer && property .mostInnerItems .isModel ) || (property .isModel ))) {
422437 continue ;
423438 }
424- String childPropertyType = property .isContainer ? property .mostInnerItems .baseType : property .baseType ;
425- for (final String key : objs .keySet ()) {
439+ String childPropertyType = property .isContainer ? property .mostInnerItems .baseType : property .baseType ;
440+ for (final String key : objs .keySet ()) {
426441 CodegenModel childModel = ModelUtils .getModelByName (key , objs );
427- if ( !childPropertyType .equals (childModel .classname ) || childPropertyType .equals (parentModel .classname ) || !childModel .hasVars ) {
442+ if ( !childPropertyType .equals (childModel .classname ) || childPropertyType .equals (parentModel .classname ) || !childModel .hasVars ) {
428443 continue ;
429444 }
430445
431446 String forwardDecl = "class " + childPropertyType + ";" ;
432- if (!forwardDeclarations .contains (forwardDecl )) {
447+ if (!forwardDeclarations .contains (forwardDecl )) {
433448 forwardDeclarations .add (forwardDecl );
434449 }
435450 }
436451 }
437- if (!forwardDeclarations .isEmpty ()){
452+ if (!forwardDeclarations .isEmpty ()) {
438453 parentModel .vendorExtensions .put ("x-has-forward-declarations" , true );
439454 parentModel .vendorExtensions .put ("x-forward-declarations" , forwardDeclarations );
440455 }
441456 return ;
442457 }
443458
444459 @ Override
445- public GeneratorLanguage generatorLanguage () { return GeneratorLanguage .C_PLUS_PLUS ; }
460+ public GeneratorLanguage generatorLanguage () {
461+ return GeneratorLanguage .C_PLUS_PLUS ;
462+ }
446463}
0 commit comments