Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/conflicting command names #1544

Merged
merged 3 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Revamped the api surface for request configuration. [#1494](https://github.com/microsoft/kiota/issues/1494)
- Fixed a bug in methods naming in Go after request configuration revamp.
- Fixes a bug where reserved names would not be updated for inheritance.
- Add `item` subcommand for indexers. Fixes conflicts when paths have repeating segments. (Shell) [#1541](https://github.com/microsoft/kiota/issues/1541)

## [0.0.23] - 2022-04-19

Expand Down
1 change: 0 additions & 1 deletion src/Kiota.Builder/Refiners/ShellRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ private static void CreateCommandBuildersFromIndexers(CodeClass currentClass, IE

// ReturnType setter assigns the parent
method.ReturnType = CreateCommandType();
method.ReturnType.CollectionKind = CodeTypeBase.CodeTypeCollectionKind.Complex;
currentClass.AddMethod(method);
currentClass.RemoveChildElement(indexer);
}
Expand Down
11 changes: 7 additions & 4 deletions src/Kiota.Builder/Writers/Shell/ShellCodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -350,26 +350,29 @@ private void WriteUnnamedBuildCommand(CodeMethod codeElement, LanguageWriter wri
}
else if (codeElement.OriginalIndexer != null)
{
writer.WriteLine($"var command = new Command(\"item\");");
var targetClass = conventions.GetTypeString(codeElement.OriginalIndexer.ReturnType, codeElement);
var builderMethods = (codeElement.OriginalIndexer.ReturnType as CodeType).TypeDefinition.GetChildElements(true).OfType<CodeMethod>()
.Where(m => m.IsOfKind(CodeMethodKind.CommandBuilder))
.OrderBy(m => m.Name);
conventions.AddRequestBuilderBody(parent, targetClass, writer, prefix: "var builder = ", pathParameters: codeElement.Parameters.Where(x => x.IsOfKind(CodeParameterKind.Path)));
writer.WriteLine("var commands = new List<Command>();");

foreach (var method in builderMethods)
{
if (method.ReturnType.IsCollection)
{
writer.WriteLine($"commands.AddRange(builder.{method.Name}());");
writer.WriteLine($"foreach (var cmd in builder.{method.Name}()) {{");
writer.IncreaseIndent();
writer.WriteLine($"command.AddCommand(cmd);");
writer.CloseBlock();
}
else
{
writer.WriteLine($"commands.Add(builder.{method.Name}());");
writer.WriteLine($"command.AddCommand(builder.{method.Name}());");
}
}

writer.WriteLine("return commands;");
writer.WriteLine("return command;");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,11 @@ public void WritesIndexerCommands() {
var result = tw.ToString();

Assert.Contains("var builder = new TestRequestBuilder", result);
Assert.Contains("var commands = new List<Command>();", result);
Assert.Contains("commands.Add(builder.BuildTestMethod1());", result);
Assert.Contains("commands.AddRange(builder.BuildTestMethod2());", result);
Assert.Contains("return commands;", result);
Assert.Contains("var command = new Command(\"item\");", result);
Assert.Contains("command.AddCommand(builder.BuildTestMethod1());", result);
Assert.Contains("foreach (var cmd in builder.BuildTestMethod2()) {", result);
Assert.Contains("command.AddCommand(cmd);", result);
Assert.Contains("return command;", result);
}

[Fact]
Expand Down