Skip to content

Commit

Permalink
- fixes reserved names replacement
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Biret <vibiret@microsoft.com>
  • Loading branch information
baywet committed Aug 9, 2023
1 parent b7bb9ff commit 5fe47b0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Kiota.Builder/Refiners/CommonLanguageRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,18 @@ protected static void CorrectNames(CodeElement current, Func<string, string> ref
ArgumentNullException.ThrowIfNull(refineName);
if (current is CodeClass currentClass && classNames &&
refineName(currentClass.Name) is string refinedClassName &&
!currentClass.Name.Equals(refinedClassName, StringComparison.Ordinal))
!currentClass.Name.Equals(refinedClassName, StringComparison.Ordinal) &&
currentClass.Parent is IBlock parentBlock)
{
currentClass.Name = refinedClassName;
parentBlock.RenameChildElement(currentClass.Name, refinedClassName);
}
else if (current is CodeEnum currentEnum &&
enumNames &&
refineName(currentEnum.Name) is string refinedEnumName &&
!currentEnum.Name.Equals(refinedEnumName, StringComparison.Ordinal))
!currentEnum.Name.Equals(refinedEnumName, StringComparison.Ordinal) &&
currentEnum.Parent is IBlock parentBlock2)
{
currentEnum.Name = refinedEnumName;
parentBlock2.RenameChildElement(currentEnum.Name, refinedEnumName);
}
CrawlTree(current, x => CorrectNames(x, refineName));
}
Expand All @@ -146,7 +148,7 @@ current.Parent is CodeClass parentClass &&

var refinedName = refineAccessorName(currentProperty.Name);
if (!parentClass.Properties.Any(property => refinedName.Equals(property.Name, StringComparison.OrdinalIgnoreCase)))// ensure the refinement won't generate a duplicate
currentProperty.Name = refinedName;
parentClass.RenameChildElement(currentProperty.Name, refinedName);
}
CrawlTree(current, x => ReplacePropertyNames(x, propertyKindsToReplace!, refineAccessorName));
}
Expand Down
1 change: 1 addition & 0 deletions src/Kiota.Builder/Refiners/RubyReservedNamesProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class RubyReservedNamesProvider : IReservedNamesProvider
"self",
"BaseRequestBuilder",
"ObjectId",
"object_id",
});
public HashSet<string> ReservedNames => _reservedNames.Value;
}

0 comments on commit 5fe47b0

Please sign in to comment.