-
Notifications
You must be signed in to change notification settings - Fork 323
Fix empty objects in plugin manifests by omitting them instead of serializing empty {} #6945
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
b2def3a
2c56a29
754ca72
c6bd1e1
6fb023f
944109e
003cf9c
369292f
491eeb2
bc1b3f9
32d6554
e149f4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "sdk": { | ||
| "version": "8.0.414", | ||
| "version": "8.0.119", | ||
| "rollForward": "latestMajor", | ||
| "allowPrerelease": false | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| using System.IO; | ||
| using System.Text.Json.Nodes; | ||
| using Kiota.Builder.OpenApiExtensions; | ||
| using Microsoft.OpenApi; | ||
| using Microsoft.OpenApi.Writers; | ||
|
Check failure on line 5 in tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiLogoExtensionTests.cs
|
||
| using Xunit; | ||
|
|
||
| namespace Kiota.Builder.Tests.OpenApiExtensions; | ||
|
|
||
| public sealed class OpenApiLogoExtensionTest | ||
| { | ||
| [Fact] | ||
| public void Parses() | ||
| { | ||
| var oaiValueRepresentation = | ||
| """ | ||
| { | ||
| "url": "https://example.com/logo.png" | ||
| } | ||
| """; | ||
| using var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(oaiValueRepresentation)); | ||
| var oaiValue = JsonNode.Parse(stream); | ||
| var value = OpenApiLogoExtension.Parse(oaiValue); | ||
|
|
||
| Assert.NotNull(value); | ||
| Assert.Equal("https://example.com/logo.png", value.Url); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void Serializes() | ||
| { | ||
| var value = new OpenApiLogoExtension | ||
| { | ||
| Url = "https://example.com/logo.png" | ||
| }; | ||
| using var sWriter = new StringWriter(); | ||
| OpenApiJsonWriter writer = new(sWriter, new OpenApiJsonWriterSettings { Terse = true }); | ||
|
|
||
| value.Write(writer, OpenApiSpecVersion.OpenApi3_0); | ||
| var result = sWriter.ToString(); | ||
|
|
||
| Assert.Equal("{\"url\":\"https://example.com/logo.png\"}", result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void WritesNothingForEmptyLogo() | ||
| { | ||
| var value = new OpenApiLogoExtension | ||
| { | ||
| Url = null | ||
| }; | ||
| using var sWriter = new StringWriter(); | ||
| OpenApiJsonWriter writer = new(sWriter, new OpenApiJsonWriterSettings { Terse = true }); | ||
|
|
||
| value.Write(writer, OpenApiSpecVersion.OpenApi3_0); | ||
| var result = sWriter.ToString(); | ||
|
|
||
| // When Url is null/empty, nothing should be written | ||
| Assert.Equal(string.Empty, result); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void WritesNothingForEmptyUrlString() | ||
| { | ||
| var value = new OpenApiLogoExtension | ||
| { | ||
| Url = string.Empty | ||
| }; | ||
| using var sWriter = new StringWriter(); | ||
| OpenApiJsonWriter writer = new(sWriter, new OpenApiJsonWriterSettings { Terse = true }); | ||
|
|
||
| value.Write(writer, OpenApiSpecVersion.OpenApi3_0); | ||
| var result = sWriter.ToString(); | ||
|
|
||
| // When Url is empty string, nothing should be written | ||
| Assert.Equal(string.Empty, result); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.