Skip to content

Commit

Permalink
- aligns set content from parsable parameters order to changes from #…
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet committed Aug 16, 2021
1 parent 5f1eca1 commit cd4db01
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions abstractions/go/request_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,13 @@ func (request *RequestInfo) SetStreamContent(content []byte) {
request.Content = content
request.Headers[contentTypeHeader] = binaryContentType
}
func (request *RequestInfo) SetContentFromParsable(item s.Parsable, coreService HttpCore, contentType string) error {
func (request *RequestInfo) SetContentFromParsable(coreService HttpCore, contentType string, items ...s.Parsable) error {
if contentType == "" {
return errors.New("content type cannot be empty")
} else if coreService == nil {
return errors.New("coreService cannot be nil")
} else if items == nil || len(items) == 0 {
return errors.New("items cannot be nil or empty")
}
factory, err := coreService.GetSerializationWriterFactory()
if err != nil {
Expand All @@ -71,7 +73,12 @@ func (request *RequestInfo) SetContentFromParsable(item s.Parsable, coreService
return errors.New("writer cannot be nil")
}
defer writer.Close()
writeErr := writer.WriteObjectValue("", item)
var writeErr error
if len(items) == 1 {
writeErr = writer.WriteObjectValue("", items[0])
} else {
writeErr = writer.WriteCollectionOfObjectValues("", items)
}
if writeErr != nil {
return writeErr
}
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ private void WriteRequestGeneratorBody(CodeMethod codeElement, CodeParameter req
if(requestBodyParam.Type.Name.Equals("binary", StringComparison.OrdinalIgnoreCase))
writer.WriteLine($"{rInfoVarName}.SetStreamContent({requestBodyParam.Name})");
else
writer.WriteLine($"{rInfoVarName}.SetContentFromParsable({requestBodyParam.Name}, m.{conventions.HttpCorePropertyName}, \"{codeElement.ContentType}\")");
writer.WriteLine($"{rInfoVarName}.SetContentFromParsable(m.{conventions.HttpCorePropertyName}, \"{codeElement.ContentType}\", {requestBodyParam.Name})");
if(queryStringParam != null) {
var httpMethodPrefix = codeElement.HttpMethod.ToString().ToFirstCharacterUpperCase();
writer.WriteLine($"if {queryStringParam.Name} != nil {{");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void WritesRequestGeneratorBody() {
Assert.Contains("qParams.AddQueryParameters(requestInfo.QueryParameters)", result);
Assert.Contains("o != nil", result);
Assert.Contains("requestInfo.AddMiddlewareOptions(o)", result);
Assert.Contains("requestInfo.SetContentFromParsable(b, m.httpCore", result);
Assert.Contains("requestInfo.SetContentFromParsable(m.httpCore", result);
Assert.Contains("return requestInfo, err", result);
AssertExtensions.CurlyBracesAreClosed(result);
}
Expand Down

0 comments on commit cd4db01

Please sign in to comment.