Skip to content

Commit

Permalink
Fix/conflicting command names (#1544)
Browse files Browse the repository at this point in the history
* Introduce item subcommand for indexers

* Remove query parameters base class
  • Loading branch information
calebkiage authored May 5, 2022
1 parent d8ff5d4 commit 550b1d6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
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
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Refiners/CommonLanguageRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ internal void DisableActionOf(CodeElement current, params CodeParameterKind[] ki

CrawlTree(current, x => DisableActionOf(x, kinds));
}
internal void AddInnerClasses(CodeElement current, bool prefixClassNameWithParentName, string queryParametersBaseClassName = "QueryParametersBase", bool addToParentNamespace = false) {
internal void AddInnerClasses(CodeElement current, bool prefixClassNameWithParentName, string queryParametersBaseClassName = "", bool addToParentNamespace = false) {
if(current is CodeClass currentClass) {
var parentNamespace = currentClass.GetImmediateParentOfType<CodeNamespace>();
var innerClasses = currentClass
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
13 changes: 8 additions & 5 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 Expand Up @@ -452,7 +455,7 @@ private static void WriteRequestInformation(LanguageWriter writer, CodeMethod ge
indentParam = false;
}

writer.Write($"q.{param.Name.ToFirstCharacterUpperCase()} = {paramName};", indentParam);
writer.Write($"q.QueryParameters.{param.Name.ToFirstCharacterUpperCase()} = {paramName};", indentParam);

writer.WriteLine();
}
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

0 comments on commit 550b1d6

Please sign in to comment.