Skip to content

Commit

Permalink
- fixes a bug wwhere the root namespace would have a null name causin…
Browse files Browse the repository at this point in the history
…g unit tests to fail
  • Loading branch information
baywet committed Mar 18, 2022
1 parent 859fb7d commit afa0305
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/Kiota.Builder/CodeDOM/CodeNamespace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ public class CodeNamespace : CodeBlock<BlockDeclaration, BlockEnd>
{
private CodeNamespace():base() {}
public static CodeNamespace InitRootNamespace() {
return new CodeNamespace();
return new() {
Name = string.Empty,
};
}
private string name;
public override string Name
Expand Down Expand Up @@ -60,19 +62,19 @@ public CodeNamespace FindNamespaceByName(string nsName) {
public CodeNamespace AddNamespace(string namespaceName) {
if(string.IsNullOrEmpty(namespaceName))
throw new ArgumentNullException(nameof(namespaceName));
var namespaceNameSegements = namespaceName.Split(namespaceNameSeparator, StringSplitOptions.RemoveEmptyEntries);
var namespaceNameSegments = namespaceName.Split(namespaceNameSeparator, StringSplitOptions.RemoveEmptyEntries);
var lastPresentSegmentIndex = default(int);
var lastPresentSegmentNamespace = GetRootNamespace();
while(lastPresentSegmentIndex < namespaceNameSegements.Length) {
var segmentNameSpace = lastPresentSegmentNamespace.FindNamespaceByName(namespaceNameSegements.Take(lastPresentSegmentIndex + 1).Aggregate((x, y) => $"{x}.{y}"));
while(lastPresentSegmentIndex < namespaceNameSegments.Length) {
var segmentNameSpace = lastPresentSegmentNamespace.FindNamespaceByName(namespaceNameSegments.Take(lastPresentSegmentIndex + 1).Aggregate((x, y) => $"{x}.{y}"));
if(segmentNameSpace == null)
break;
else {
lastPresentSegmentNamespace = segmentNameSpace;
lastPresentSegmentIndex++;
}
}
foreach(var childSegment in namespaceNameSegements.Skip(lastPresentSegmentIndex))
foreach(var childSegment in namespaceNameSegments.Skip(lastPresentSegmentIndex))
lastPresentSegmentNamespace = lastPresentSegmentNamespace
.AddRange(
new CodeNamespace {
Expand Down

0 comments on commit afa0305

Please sign in to comment.