Skip to content
Merged
Changes from all 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
13 changes: 11 additions & 2 deletions powershell/llcsharp/operation/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ export class OperationMethod extends Method {
yield 'request.Content = new System.Net.Http.StreamContent(body);';
yield 'request.Content.Headers.ContentType = System.Net.Http.Headers.MediaTypeHeaderValue.Parse(!string.IsNullOrEmpty(contentType)? contentType : mimeType);';
} else {
// This block is only supposed to be applied on requests that have a body parameter
if (method.capitalize() === 'Post' || method.capitalize() === 'Put' || method.capitalize() === 'Patch') {

if (bp.typeDeclaration.schema.type === 'object' && (method.capitalize() === 'Post' || method.capitalize() === 'Put' || method.capitalize() === 'Patch')) {
yield 'string cleanedBody = "@{}";';
yield 'if (body != null) {';
yield ' cleanedBody = body.ToJson(null).ToString();';
Expand All @@ -360,6 +360,15 @@ export class OperationMethod extends Method {
yield ' cleanedBody = Microsoft.Graph.PowerShell.JsonUtilities.JsonExtensions.RemoveDefaultNullProperties(jsonObject);';
yield '}';
yield EOL;
} else if (bp.typeDeclaration.schema.type === 'array' && (method.capitalize() === 'Post' || method.capitalize() === 'Put' || method.capitalize() === 'Patch')) {
yield 'string cleanedBody = "@[{}]";';
yield 'if (body != null) {';
yield ' cleanedBody = new Microsoft.Graph.PowerShell.Runtime.Json.XNodeArray(global::System.Linq.Enumerable.ToArray(System.Linq.Enumerable.Select(body, (__x) => __x?.ToJson(null, Microsoft.Graph.PowerShell.Runtime.SerializationMode.None)))).ToString();';
yield ' cleanedBody = Microsoft.Graph.PowerShell.JsonUtilities.JsonExtensions.ReplaceAndRemoveSlashes(cleanedBody);';
yield ' Newtonsoft.Json.Linq.JArray jsonArray = Newtonsoft.Json.Linq.JArray.Parse(cleanedBody);';
yield ' cleanedBody = Microsoft.Graph.PowerShell.JsonUtilities.JsonExtensions.RemoveDefaultNullProperties(jsonArray);';
yield '}';
yield EOL;
}
yield '// set body content';
yield `request.Content = ${bp.serializeToContent(bp.mediaType, ClientRuntime.SerializationMode.None)};`;
Expand Down