@@ -625,10 +625,11 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
625625
626626 CodegenComposedSchemas composedSchemas = model .getComposedSchemas ();
627627 if (composedSchemas != null ) {
628+ Set <String > composedPropertyNames = new HashSet <String >();
628629 List <CodegenProperty > allOf = composedSchemas .getAllOf ();
629630 if (allOf != null ) {
630631 for (CodegenProperty property : allOf ) {
631- property .name = patchPropertyName (model , camelize (property .baseType ));
632+ property .name = patchPropertyName (model , camelize (property .baseType ), composedPropertyNames );
632633 patchPropertyVendorExtensions (property );
633634 }
634635 }
@@ -637,7 +638,7 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
637638 if (anyOf != null ) {
638639 removePropertiesDeclaredInComposedTypes (objs , model , anyOf );
639640 for (CodegenProperty property : anyOf ) {
640- property .name = patchPropertyName (model , camelize (property .baseType ));
641+ property .name = patchPropertyName (model , camelize (property .baseType ), composedPropertyNames );
641642 property .isNullable = true ;
642643 patchPropertyVendorExtensions (property );
643644 property .vendorExtensions .put ("x-base-name" , model .name .substring (model .name .lastIndexOf ('_' ) + 1 ));
@@ -648,7 +649,7 @@ public Map<String, ModelsMap> postProcessAllModels(Map<String, ModelsMap> objs)
648649 if (oneOf != null ) {
649650 removePropertiesDeclaredInComposedTypes (objs , model , oneOf );
650651 for (CodegenProperty property : oneOf ) {
651- property .name = patchPropertyName (model , camelize (property .baseType ));
652+ property .name = patchPropertyName (model , camelize (property .baseType ), composedPropertyNames );
652653 property .isNullable = true ;
653654 patchPropertyVendorExtensions (property );
654655 property .vendorExtensions .put ("x-base-name" , model .name .substring (model .name .lastIndexOf ('_' ) + 1 ));
@@ -715,13 +716,27 @@ private boolean modelIsMutable(CodegenModel model, Set<String> processed) {
715716 protected void removePropertiesDeclaredInComposedTypes (Map <String , ModelsMap > objs , CodegenModel model , List <CodegenProperty > composedProperties ) {
716717 }
717718
718- private String patchPropertyName (CodegenModel model , String value ) {
719+ private String patchPropertyName (CodegenModel model , String value , Set < String > composedPropertyNames ) {
719720 String name = escapeReservedWord (model , value );
720721
721722 if (name .startsWith (AbstractCSharpCodegen .invalidParameterNamePrefix )) {
722723 name = AbstractCSharpCodegen .invalidPropertyNamePrefix + name .substring (AbstractCSharpCodegen .invalidParameterNamePrefix .length ());
723724 }
724725
726+ // ensure the name we use for a composed property does not already exist as a property or composed property
727+ // only do this if the set of composed property names was provided to ensure this method is idempotent
728+ // we would not calling this method multiple times to result in different values
729+ if (composedPropertyNames != null ) {
730+ String tmpName = name ;
731+ long count = model .allVars .stream ().map (v -> v .name ).filter (n -> n .equals (tmpName )).count () + composedPropertyNames .stream ().filter (n -> n .equals (tmpName )).count ();
732+
733+ if (count > 0 ) {
734+ name = name + count ++;
735+ }
736+
737+ composedPropertyNames .add (name );
738+ }
739+
725740 return name ;
726741 }
727742
@@ -753,7 +768,7 @@ protected void patchProperty(Map<String, CodegenModel> enumRefs, CodegenModel mo
753768
754769 patchPropertyVendorExtensions (property );
755770
756- property .name = patchPropertyName (model , property .name );
771+ property .name = patchPropertyName (model , property .name , null );
757772
758773 String [] nestedTypes = {"List" , "Collection" , "ICollection" , "Dictionary" };
759774
0 commit comments