Skip to content

Commit

Permalink
Merge pull request #2173 from microsoft/php/multi-value-headers
Browse files Browse the repository at this point in the history
Multi-Value headers support for PHP Generation
  • Loading branch information
SilasKenneth authored Jan 23, 2023
2 parents fb09e56 + 7a405d2 commit d0c64cc
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added support for external documentation links on request execution methods (PHP Generation). [2038](https://github.com/microsoft/kiota/issues/2138)
- Adds support for nullable reference types in dotnet for projects running Netstandard 2.1/Net 6.0 and above []()
- Added support for multi-value headers to CLI generation. (Shell)
- Add support for multi-value headers for PHP Generation. [#2052](https://github.com/microsoft/kiota/issues/2052)

### Changed

Expand All @@ -25,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Renamed CreateXXXRequestInformation methods to ToXXXRequestInformation for a better auto-completion experience. [#2071](https://github.com/microsoft/kiota/issues/2071)
- Renamed Go request adapter methods to remove the async suffix. [#2084](https://github.com/microsoft/kiota/issues/2084)
- Fixed a bug where CLI query/header/path parameters would not be deduplicated. [#2059](https://github.com/microsoft/kiota/issues/2059)
- Removes unused generated import for PHP Generation.

## [0.10.0] - 2023-01-04

Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Refiners/PhpRefiner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public override Task Refine(CodeNamespace generatedCode, CancellationToken cance
new (x => x is CodeProperty prop && prop.IsOfKind(CodePropertyKind.RequestAdapter),
"Microsoft\\Kiota\\Abstractions", "RequestAdapter"),
new (x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.RequestGenerator),
"Microsoft\\Kiota\\Abstractions", "HttpMethod", "RequestInformation", "RequestOption"),
"Microsoft\\Kiota\\Abstractions", "HttpMethod", "RequestInformation"),
new (x => x is CodeMethod method && method.IsOfKind(CodeMethodKind.RequestExecutor),
"Microsoft\\Kiota\\Abstractions", "ResponseHandler"),
new (static x => x is CodeClass @class && @class.IsOfKind(CodeClassKind.Model) && @class.Properties.Any(static y => y.IsOfKind(CodePropertyKind.AdditionalData)),
Expand Down
4 changes: 2 additions & 2 deletions src/Kiota.Builder/Writers/Php/CodeMethodWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ private void WriteRequestConfiguration(RequestParams requestParams, LanguageWrit
var headersName = $"{requestConfigParamName}->{headers.Name.ToFirstCharacterLowerCase()}";
writer.WriteLine($"if ({headersName} !== null) {{");
writer.IncreaseIndent();
writer.WriteLine($"{RequestInfoVarName}->headers = array_merge({RequestInfoVarName}->headers, {headersName});");
writer.WriteLine($"{RequestInfoVarName}->addHeaders({headersName});");
writer.CloseBlock();
}
if (queryString != null)
Expand All @@ -398,7 +398,7 @@ private void WriteRequestConfiguration(RequestParams requestParams, LanguageWrit
private void WriteAcceptHeaderDef(CodeMethod codeMethod, LanguageWriter writer)
{
if(codeMethod.AcceptedResponseTypes.Any())
writer.WriteLine($"{RequestInfoVarName}->headers = array_merge({RequestInfoVarName}->headers, [\"Accept\" => \"{string.Join(", ", codeMethod.AcceptedResponseTypes)}\"]);");
writer.WriteLine($"{RequestInfoVarName}->headers->addHeader('Accept', \"{string.Join(", ", codeMethod.AcceptedResponseTypes)}\");");
}
private void WriteDeserializerBody(CodeClass parentClass, LanguageWriter writer, CodeMethod method) {
var inherits = parentClass.StartBlock?.Inherits != null;
Expand Down
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Writers/Php/CodePropertyWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private string GetCollectionDocString(CodeProperty codeProperty)
{
CodePropertyKind.AdditionalData => "array<string, mixed>",
CodePropertyKind.PathParameters => "array<string, mixed>",
CodePropertyKind.Headers => "array<string, string>",
CodePropertyKind.Headers => "array<string, array<string>|string>",
CodePropertyKind.Options => "array<string, RequestOption>",
_ => $"array<{conventions.TranslateType(codeProperty.Type)}>"
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ public void WriteRequestGeneratorForParsable()
result);
Assert.Contains("if ($requestConfiguration !== null", result);
Assert.Contains("if ($requestConfiguration->h !== null)", result);
Assert.Contains("$requestInfo->headers = array_merge($requestInfo->headers, $requestConfiguration->h);", result);
Assert.Contains("$requestInfo->addHeaders($requestConfiguration->h);", result);
Assert.Contains("$requestInfo->setQueryParameters($requestConfiguration->q);", result);
Assert.Contains("$requestInfo->addRequestOptions(...$requestConfiguration->o);", result);
Assert.Contains("$requestInfo->setContentFromParsable($this->requestAdapter, \"\", $body);", result);
Expand All @@ -415,7 +415,7 @@ public void WritesRequestGeneratorBodyForParsableCollection()
result);
Assert.Contains("if ($requestConfiguration !== null", result);
Assert.Contains("if ($requestConfiguration->h !== null)", result);
Assert.Contains("$requestInfo->headers = array_merge($requestInfo->headers, $requestConfiguration->h);", result);
Assert.Contains("$requestInfo->addHeaders($requestConfiguration->h);", result);
Assert.Contains("$requestInfo->setQueryParameters($requestConfiguration->q);", result);
Assert.Contains("$requestInfo->addRequestOptions(...$requestConfiguration->o);", result);
Assert.Contains("$requestInfo->setContentFromParsableCollection($this->requestAdapter, \"\", $body);", result);
Expand All @@ -441,7 +441,7 @@ public void WriteRequestGeneratorForScalarType()
result);
Assert.Contains("if ($requestConfiguration !== null", result);
Assert.Contains("if ($requestConfiguration->h !== null)", result);
Assert.Contains("$requestInfo->headers = array_merge($requestInfo->headers, $requestConfiguration->h);", result);
Assert.Contains("$requestInfo->addHeaders($requestConfiguration->h);", result);
Assert.Contains("$requestInfo->setQueryParameters($requestConfiguration->q);", result);
Assert.Contains("$requestInfo->addRequestOptions(...$requestConfiguration->o);", result);
Assert.Contains("$requestInfo->setContentFromScalar($this->requestAdapter, \"\", $body);", result);
Expand Down Expand Up @@ -472,7 +472,7 @@ public void WritesRequestGeneratorBodyForScalarCollection()
result);
Assert.Contains("if ($requestConfiguration !== null", result);
Assert.Contains("if ($requestConfiguration->h !== null)", result);
Assert.Contains("$requestInfo->headers = array_merge($requestInfo->headers, $requestConfiguration->h);", result);
Assert.Contains("$requestInfo->addHeaders($requestConfiguration->h);", result);
Assert.Contains("$requestInfo->setQueryParameters($requestConfiguration->q);", result);
Assert.Contains("$requestInfo->addRequestOptions(...$requestConfiguration->o);", result);
Assert.Contains("$requestInfo->setContentFromScalarCollection($this->requestAdapter, \"\", $body);", result);
Expand Down

0 comments on commit d0c64cc

Please sign in to comment.