Skip to content

Commit

Permalink
Merge pull request #13 from microsoft/bugfix/empty-query-params
Browse files Browse the repository at this point in the history
- fixes a bug where empty query parameters would be passed
  • Loading branch information
baywet authored Apr 7, 2022
2 parents 6c13083 + 36f36d3 commit 0bc68bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Microsoft.Kiota.Abstractions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<Deterministic>true</Deterministic>
<VersionPrefix>1.0.0</VersionPrefix>
<VersionSuffix>preview.3</VersionSuffix>
<VersionSuffix>preview.4</VersionSuffix>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<SignAssembly>false</SignAssembly>
<DelaySign>false</DelaySign>
Expand All @@ -23,7 +23,7 @@
<!-- Enable this line once we go live to prevent breaking changes -->
<!-- <PackageValidationBaselineVersion>1.0.0</PackageValidationBaselineVersion> -->
<PackageReleaseNotes>
- Breaking: simplifies the field deserializers.
- Adds support for query parameters name attribute.
</PackageReleaseNotes>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
Expand Down
15 changes: 10 additions & 5 deletions src/QueryParametersBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@ public void AddQueryParameters(IDictionary<string, object> target)
if(target == null) throw new ArgumentNullException(nameof(target));
foreach(var property in this.GetType()
.GetProperties()
.Where(x => !target.ContainsKey(x.Name)))
.Select(
x => (
Name: x.GetCustomAttributes(false)
.OfType<QueryParameterAttribute>()
.FirstOrDefault()?.TemplateName ?? x.Name.ToFirstCharacterLowerCase(),
Value: x.GetValue(this)
)
)
.Where(x => x.Value != null && !target.ContainsKey(x.Name)))
{
var attribute = property.GetCustomAttributes(false)
.OfType<QueryParameterAttribute>()
.FirstOrDefault();
target.Add(attribute?.TemplateName ?? property.Name.ToFirstCharacterLowerCase(), property.GetValue(this));
target.Add(property.Name, property.Value);
}
}
}
Expand Down

0 comments on commit 0bc68bd

Please sign in to comment.