Skip to content

Commit

Permalink
Fix an issue with collection models failing type checking (microsoft#…
Browse files Browse the repository at this point in the history
…2775)

* Fix an issue with collection models failing type checking (Shell)
  • Loading branch information
calebkiage authored Jun 16, 2023
1 parent a66f8b3 commit c45f8d2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Writers/Shell/ShellCodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ protected virtual void WriteCommandHandlerBody(CodeMethod codeElement, CodeClass

if (requestBodyParamType.IsCollection)
{
writer.WriteLine($"var model = parseNode.GetCollectionOfObjectValues<{typeString}>({typeString}.CreateFromDiscriminatorValue);");
writer.WriteLine($"var model = parseNode.GetCollectionOfObjectValues<{typeString}>({typeString}.CreateFromDiscriminatorValue)?.ToList();");
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ public void WritesExecutableCommandForPostRequestWithCollectionModel()
Assert.Contains("command.AddOption(bodyOption);", result);
Assert.Contains("var body = invocationContext.ParseResult.GetValueForOption(bodyOption) ?? string.Empty;", result);
Assert.Contains("using var stream = new MemoryStream(Encoding.UTF8.GetBytes(body));", result);
Assert.Contains("var model = parseNode.GetCollectionOfObjectValues<Content>(Content.CreateFromDiscriminatorValue);", result);
Assert.Contains("var model = parseNode.GetCollectionOfObjectValues<Content>(Content.CreateFromDiscriminatorValue)?.ToList();", result);
Assert.Contains("if (model is null) return;", result);
Assert.Contains("var requestInfo = CreatePostRequestInformation", result);
Assert.Contains("if (testPath is not null) requestInfo.PathParameters.Add(\"test%2Dpath\", testPath);", result);
Expand Down

0 comments on commit c45f8d2

Please sign in to comment.