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

- fixes missing content type parameter bug #3611

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed missing imports for method parameters that are query parameters.
- Replaces the use of "new" by "override" and "virtual" in CSharp models.
- Fixed a bug in validation rules where form data would wrongfully warn for arrays. [#3569](https://github.com/microsoft/kiota/issues/3569)
- Fixed a bug where content type parameter would be missing for TypeScript, Java, PHP, Python, Ruby and Go. [#3610](https://github.com/microsoft/kiota/issues/3610)
- Fixed query parameters type mapping for arrays. [#3354](https://github.com/microsoft/kiota/issues/3354)
- The lock file now contains the relative path to the description in case of local path. [#3151](https://github.com/microsoft/kiota/issues/3151)
- Fixes a bug where query parameters would be missing in CSharp for ebc clients. [#3583](https://github.com/microsoft/kiota/issues/3583)
Expand Down
8 changes: 5 additions & 3 deletions src/Kiota.Builder/Writers/Go/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -793,10 +793,12 @@ private static void WriteMethodCall(CodeMethod codeElement, RequestParams reques
?.Name
?.ToFirstCharacterUpperCase();
var paramsList = new List<CodeParameter?> { codeElement.Parameters.OfKind(CodeParameterKind.Cancellation), requestParams.requestBody, requestParams.requestConfiguration };
if (requestParams.requestContentType is not null)
paramsList.Insert(2, requestParams.requestContentType);
if (parametersPad > 0)
paramsList.AddRange(Enumerable.Range(0, parametersPad).Select<int, CodeParameter?>(x => null));
var requestInfoParameters = paramsList.Where(static x => x != null)
.Select(static x => x!.Name)
paramsList.AddRange(Enumerable.Range(0, parametersPad).Select<int, CodeParameter?>(static x => null));
var requestInfoParameters = paramsList.OfType<CodeParameter>()
.Select(static x => x.Name)
.ToList();
var skipIndex = requestParams.requestBody == null ? 1 : 0;
requestInfoParameters.AddRange(paramsList.Where(static x => x == null).Skip(skipIndex).Select(static x => "nil"));
Expand Down
20 changes: 11 additions & 9 deletions src/Kiota.Builder/Writers/Java/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -525,17 +525,19 @@ private string GetSendRequestMethodName(bool isCollection, string returnType, bo
private static void WriteGeneratorOrExecutorMethodCall(CodeMethod codeElement, RequestParams requestParams, CodeClass parentClass, LanguageWriter writer, string prefix, CodeMethodKind codeMethodKind)
{
var methodName = parentClass
.Methods
.FirstOrDefault(x => x.IsOfKind(codeMethodKind) && x.HttpMethod == codeElement.HttpMethod)
?.Name
?.ToFirstCharacterLowerCase();
var paramsList = new[] { requestParams.requestBody, requestParams.requestConfiguration };
var requestInfoParameters = paramsList.Where(x => x != null)
.Select(x => x!.Name)
.Methods
.FirstOrDefault(x => x.IsOfKind(codeMethodKind) && x.HttpMethod == codeElement.HttpMethod)
?.Name
?.ToFirstCharacterLowerCase();
var paramsList = new List<CodeParameter?> { requestParams.requestBody, requestParams.requestConfiguration };
if (requestParams.requestContentType is not null)
paramsList.Insert(1, requestParams.requestContentType);
var requestInfoParameters = paramsList.OfType<CodeParameter>()
.Select(static x => x.Name)
.ToList();
var skipIndex = requestParams.requestBody == null ? 1 : 0;
requestInfoParameters.AddRange(paramsList.Where(x => x == null).Skip(skipIndex).Select(x => "null"));
var paramsCall = requestInfoParameters.Any() ? requestInfoParameters.Aggregate((x, y) => $"{x}, {y}") : string.Empty;
requestInfoParameters.AddRange(paramsList.Where(static x => x == null).Skip(skipIndex).Select(static x => "null"));
var paramsCall = requestInfoParameters.Any() ? requestInfoParameters.Aggregate(static (x, y) => $"{x}, {y}") : string.Empty;
writer.WriteLine($"{prefix}{methodName}({paramsCall});");
}
private void WriteRequestGeneratorBody(CodeMethod codeElement, RequestParams requestParams, CodeClass currentClass, LanguageWriter writer)
Expand Down
10 changes: 5 additions & 5 deletions src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -726,14 +726,14 @@ private void WriteRequestExecutorBody(CodeMethod codeElement, CodeClass parentCl
.FirstOrDefault(x =>
x.IsOfKind(CodeMethodKind.RequestGenerator) && x.HttpMethod == codeElement.HttpMethod);
var generatorMethodName = generatorMethod?.Name.ToFirstCharacterLowerCase();
var requestInfoParameters = new[] { requestParams.requestBody, requestParams.requestConfiguration }
.Where(static x => x?.Name != null)
.Select(static x => x!);
var callParams = requestInfoParameters.Select(conventions.GetParameterName);
var requestInfoParameters = new CodeParameter?[] { requestParams.requestBody, requestParams.requestContentType, requestParams.requestConfiguration }
.OfType<CodeParameter>()
.Select(conventions.GetParameterName)
.ToArray();
var joinedParams = string.Empty;
if (requestInfoParameters.Any())
{
joinedParams = string.Join(", ", callParams);
joinedParams = string.Join(", ", requestInfoParameters);
}

var returnTypeName = conventions.GetTypeString(codeElement.ReturnType, codeElement, false);
Expand Down
10 changes: 5 additions & 5 deletions src/Kiota.Builder/Writers/Python/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,14 +562,14 @@ private void WriteRequestExecutorBody(CodeMethod codeElement, RequestParams requ
.FirstOrDefault(x => x.IsOfKind(CodeMethodKind.RequestGenerator) && x.HttpMethod == codeElement.HttpMethod)
?.Name;
writer.WriteLine($"request_info = self.{generatorMethodName}(");
var requestInfoParameters = new[] { requestParams.requestBody, requestParams.requestConfiguration }
.Where(static x => x != null)
.Select(static x => x!.Name)
var requestInfoParameters = new CodeParameter?[] { requestParams.requestBody, requestParams.requestContentType, requestParams.requestConfiguration }
.OfType<CodeParameter>()
.Select(static x => x.Name)
.ToArray();
if (requestInfoParameters.Any() && requestInfoParameters.Aggregate(static (x, y) => $"{x}, {y}") is string parameters)
if (requestInfoParameters.Any())
{
writer.IncreaseIndent();
writer.WriteLine(parameters);
writer.WriteLine(requestInfoParameters.Aggregate(static (x, y) => $"{x}, {y}"));
writer.DecreaseIndent();
}
writer.WriteLine(")");
Expand Down
6 changes: 3 additions & 3 deletions src/Kiota.Builder/Writers/Ruby/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ private void WriteRequestExecutorBody(CodeMethod codeElement, RequestParams requ
?.Name
?.ToSnakeCase();
writer.WriteLine($"request_info = self.{generatorMethodName}(");
var requestInfoParameters = new[] { requestParams.requestBody, requestParams.requestConfiguration }
.Where(static x => x != null)
.Select(static x => x!.Name.ToSnakeCase())
var requestInfoParameters = new CodeParameter?[] { requestParams.requestBody, requestParams.requestContentType, requestParams.requestConfiguration }
.OfType<CodeParameter>()
.Select(static x => x.Name.ToSnakeCase())
.ToArray();
if (requestInfoParameters.Any())
{
Expand Down
9 changes: 5 additions & 4 deletions src/Kiota.Builder/Writers/TypeScript/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,14 @@ private void WriteRequestExecutorBody(CodeMethod codeElement, CodeClass parentCl
?.Name
?.ToFirstCharacterLowerCase();
writer.WriteLine($"const requestInfo = this.{generatorMethodName}(");
var requestInfoParameters = new[] { requestParams.requestBody, requestParams.requestConfiguration }
.Select(x => x?.Name).Where(x => x != null)
var requestInfoParameters = new CodeParameter?[] { requestParams.requestBody, requestParams.requestContentType, requestParams.requestConfiguration }
.OfType<CodeParameter>()
.Select(static x => x.Name)
.ToArray();
if (requestInfoParameters.Any() && requestInfoParameters.Aggregate((x, y) => $"{x}, {y}") is string requestInfoParametersString)
if (requestInfoParameters.Any())
{
writer.IncreaseIndent();
writer.WriteLine(requestInfoParametersString);
writer.WriteLine(requestInfoParameters.Aggregate(static (x, y) => $"{x}, {y}"));
writer.DecreaseIndent();
}
writer.WriteLine(");");
Expand Down
Loading