From a18bb778cbc8c8f6499b6287f597506d74271d22 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 13 Oct 2023 21:34:20 +0200 Subject: [PATCH 1/6] Fix that XML comment examples do not show up if the type is string and the example contains quotation marks --- .../XmlComments/XmlCommentsExampleHelper.cs | 27 ++++++++++ .../XmlComments/XmlCommentsParameterFilter.cs | 12 +---- .../XmlCommentsRequestBodyFilter.cs | 12 +---- .../XmlComments/XmlCommentsSchemaFilter.cs | 6 +-- ...akeConstructedControllerWithXmlComments.cs | 4 +- .../Fixtures/FakeControllerWithXmlComments.cs | 2 +- .../XmlCommentsExampleHelperTests.cs | 54 +++++++++++++++++++ .../XmlCommentsParameterFilterTests.cs | 4 +- .../XmlCommentsRequestBodyFilterTests.cs | 4 +- 9 files changed, 93 insertions(+), 32 deletions(-) create mode 100644 src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsExampleHelper.cs create mode 100644 test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsExampleHelperTests.cs diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsExampleHelper.cs b/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsExampleHelper.cs new file mode 100644 index 0000000000..fc7b17b2c8 --- /dev/null +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsExampleHelper.cs @@ -0,0 +1,27 @@ +using System.Text.Json; +using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Models; + +namespace Swashbuckle.AspNetCore.SwaggerGen +{ + public static class XmlCommentsExampleHelper + { + public static IOpenApiAny Create( + SchemaRepository schemaRepository, + OpenApiSchema schema, + string exampleString) + { + var isStringType = + (schema.ResolveType(schemaRepository) == "string") && + !exampleString.Equals("null"); + + var exampleAsJson = isStringType + ? JsonSerializer.Serialize(exampleString) + : exampleString; + + var example = OpenApiAnyFactory.CreateFromJson(exampleAsJson); + + return example; + } + } +} diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsParameterFilter.cs b/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsParameterFilter.cs index 58e00c31c8..1e3c7dee15 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsParameterFilter.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsParameterFilter.cs @@ -42,11 +42,7 @@ private void ApplyPropertyTags(OpenApiParameter parameter, ParameterFilterContex var exampleNode = propertyNode.SelectSingleNode("example"); if (exampleNode == null) return; - var exampleAsJson = (parameter.Schema?.ResolveType(context.SchemaRepository) == "string") - ? $"\"{exampleNode.ToString()}\"" - : exampleNode.ToString(); - - parameter.Example = OpenApiAnyFactory.CreateFromJson(exampleAsJson); + parameter.Example = XmlCommentsExampleHelper.Create(context.SchemaRepository, parameter.Schema, exampleNode.ToString()); } private void ApplyParamTags(OpenApiParameter parameter, ParameterFilterContext context) @@ -71,11 +67,7 @@ private void ApplyParamTags(OpenApiParameter parameter, ParameterFilterContext c var example = paramNode.GetAttribute("example", ""); if (string.IsNullOrEmpty(example)) return; - var exampleAsJson = (parameter.Schema?.ResolveType(context.SchemaRepository) == "string") - ? $"\"{example}\"" - : example; - - parameter.Example = OpenApiAnyFactory.CreateFromJson(exampleAsJson); + parameter.Example = XmlCommentsExampleHelper.Create(context.SchemaRepository, parameter.Schema, example.ToString()); } } } diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsRequestBodyFilter.cs b/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsRequestBodyFilter.cs index 5640cbda42..dcd4f96267 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsRequestBodyFilter.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsRequestBodyFilter.cs @@ -50,11 +50,7 @@ private void ApplyPropertyTags(OpenApiRequestBody requestBody, RequestBodyFilter foreach (var mediaType in requestBody.Content.Values) { - var exampleAsJson = (mediaType.Schema?.ResolveType(context.SchemaRepository) == "string") - ? $"\"{exampleNode.ToString()}\"" - : exampleNode.ToString(); - - mediaType.Example = OpenApiAnyFactory.CreateFromJson(exampleAsJson); + mediaType.Example = XmlCommentsExampleHelper.Create(context.SchemaRepository, mediaType.Schema, exampleNode.ToString()); } } @@ -82,11 +78,7 @@ private void ApplyParamTags(OpenApiRequestBody requestBody, RequestBodyFilterCon foreach (var mediaType in requestBody.Content.Values) { - var exampleAsJson = (mediaType.Schema?.ResolveType(context.SchemaRepository) == "string") - ? $"\"{example}\"" - : example; - - mediaType.Example = OpenApiAnyFactory.CreateFromJson(exampleAsJson); + mediaType.Example = XmlCommentsExampleHelper.Create(context.SchemaRepository, mediaType.Schema, example); } } } diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsSchemaFilter.cs b/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsSchemaFilter.cs index ddf25405e2..4075034e27 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsSchemaFilter.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsSchemaFilter.cs @@ -69,11 +69,7 @@ private static void TrySetExample(OpenApiSchema schema, SchemaFilterContext cont if (example == null) return; - var exampleAsJson = (schema.ResolveType(context.SchemaRepository) == "string") && !example.Equals("null") - ? $"\"{example}\"" - : example; - - schema.Example = OpenApiAnyFactory.CreateFromJson(exampleAsJson); + schema.Example = XmlCommentsExampleHelper.Create(context.SchemaRepository, schema, example); } } } diff --git a/test/Swashbuckle.AspNetCore.SwaggerGen.Test/Fixtures/FakeConstructedControllerWithXmlComments.cs b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/Fixtures/FakeConstructedControllerWithXmlComments.cs index 9c331aa73f..f759e38c2a 100644 --- a/test/Swashbuckle.AspNetCore.SwaggerGen.Test/Fixtures/FakeConstructedControllerWithXmlComments.cs +++ b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/Fixtures/FakeConstructedControllerWithXmlComments.cs @@ -17,8 +17,8 @@ public class GenericControllerWithXmlComments public void ActionWithSummaryAndResponseTags(T param) { } - /// Description for param1 - /// Description for param2 + /// Description for param1 + /// Description for param2 public void ActionWithParamTags(T param1, T param2) { } } diff --git a/test/Swashbuckle.AspNetCore.SwaggerGen.Test/Fixtures/FakeControllerWithXmlComments.cs b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/Fixtures/FakeControllerWithXmlComments.cs index 6d9cd92377..431b33333c 100644 --- a/test/Swashbuckle.AspNetCore.SwaggerGen.Test/Fixtures/FakeControllerWithXmlComments.cs +++ b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/Fixtures/FakeControllerWithXmlComments.cs @@ -18,7 +18,7 @@ public class FakeControllerWithXmlComments public void ActionWithSummaryAndRemarksTags() { } - /// Description for param1 + /// Description for param1 /// Description for param2 public void ActionWithParamTags(string param1, string param2) { } diff --git a/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsExampleHelperTests.cs b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsExampleHelperTests.cs new file mode 100644 index 0000000000..50d9b59bad --- /dev/null +++ b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsExampleHelperTests.cs @@ -0,0 +1,54 @@ +using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Models; +using Xunit; + +namespace Swashbuckle.AspNetCore.SwaggerGen.Test +{ + public class XmlCommentsExampleHelperTests + { + private readonly SchemaRepository schemaRepository = new SchemaRepository(); + + [Fact] + public void Create_BuildsOpenApiArrayJson__When_NotStringTypeAndDataIsArray() + { + OpenApiSchema schema = new OpenApiSchema(); + + IOpenApiAny example = XmlCommentsExampleHelper.Create( + schemaRepository, + schema, + "[\"one\",\"two\",\"three\"]"); + + + var output = (OpenApiArray)example; + Assert.Equal(3, output.Count); + Assert.Equal("one", ((OpenApiString)output[0]).Value); + Assert.Equal("two", ((OpenApiString)output[1]).Value); + Assert.Equal("three", ((OpenApiString)output[2]).Value); + } + + [Fact] + public void Create_BuildsOpenApiString_When_TypeString() + { + string exampleString = "example string with special characters\"<>\r\n\""; + OpenApiSchema schema = new OpenApiSchema { Type = "string" }; + schemaRepository.AddDefinition("test", schema); + + IOpenApiAny example = XmlCommentsExampleHelper.Create( + schemaRepository, schema, exampleString); + + Assert.Equal(((OpenApiString)example).Value, exampleString); + } + + [Fact] + public void Create_ReturnsNull_When_TypeString_and_ValueNull() + { + OpenApiSchema schema = new OpenApiSchema { Type = "string" }; + schemaRepository.AddDefinition("test", schema); + + IOpenApiAny example = XmlCommentsExampleHelper.Create( + schemaRepository, schema, "null"); + + Assert.Equal(AnyType.Null, ((OpenApiNull)example).AnyType); + } + } +} diff --git a/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsParameterFilterTests.cs b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsParameterFilterTests.cs index f27613e293..77502b15ab 100644 --- a/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsParameterFilterTests.cs +++ b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsParameterFilterTests.cs @@ -23,7 +23,7 @@ public void Apply_SetsDescriptionAndExample_FromActionParamTag() Assert.Equal("Description for param1", parameter.Description); Assert.NotNull(parameter.Example); - Assert.Equal("\"Example for param1\"", parameter.Example.ToJson()); + Assert.Equal("\"Example for \\\"param1\\\"\"", parameter.Example.ToJson()); } [Fact] @@ -57,7 +57,7 @@ public void Apply_SetsDescriptionAndExample_FromUnderlyingGenericTypeActionParam Assert.Equal("Description for param1", parameter.Description); Assert.NotNull(parameter.Example); - Assert.Equal("\"Example for param1\"", parameter.Example.ToJson()); + Assert.Equal("\"Example for \\\"param1\\\"\"", parameter.Example.ToJson()); } [Fact] diff --git a/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsRequestBodyFilterTests.cs b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsRequestBodyFilterTests.cs index 73995e32da..9d4bd7dabf 100644 --- a/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsRequestBodyFilterTests.cs +++ b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsRequestBodyFilterTests.cs @@ -34,7 +34,7 @@ public void Apply_SetsDescriptionAndExample_FromActionParamTag() Assert.Equal("Description for param1", requestBody.Description); Assert.NotNull(requestBody.Content["application/json"].Example); - Assert.Equal("\"Example for param1\"", requestBody.Content["application/json"].Example.ToJson()); + Assert.Equal("\"Example for \\\"param1\\\"\"", requestBody.Content["application/json"].Example.ToJson()); } [Fact] @@ -60,7 +60,7 @@ public void Apply_SetsDescriptionAndExample_FromUnderlyingGenericTypeActionParam Assert.Equal("Description for param1", requestBody.Description); Assert.NotNull(requestBody.Content["application/json"].Example); - Assert.Equal("\"Example for param1\"", requestBody.Content["application/json"].Example.ToJson()); + Assert.Equal("\"Example for \\\"param1\\\"\"", requestBody.Content["application/json"].Example.ToJson()); } [Fact] From 6f6837cb0e35cdcb9addcabbbfc8b699598c13ed Mon Sep 17 00:00:00 2001 From: Daniel Date: Tue, 17 Oct 2023 17:45:25 +0200 Subject: [PATCH 2/6] allow schema to be null in example creation --- .../XmlComments/XmlCommentsExampleHelper.cs | 2 +- .../XmlComments/XmlCommentsParameterFilter.cs | 2 +- .../XmlComments/XmlCommentsExampleHelperTests.cs | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsExampleHelper.cs b/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsExampleHelper.cs index fc7b17b2c8..185953afdb 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsExampleHelper.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsExampleHelper.cs @@ -12,7 +12,7 @@ public static IOpenApiAny Create( string exampleString) { var isStringType = - (schema.ResolveType(schemaRepository) == "string") && + (schema?.ResolveType(schemaRepository) == "string") && !exampleString.Equals("null"); var exampleAsJson = isStringType diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsParameterFilter.cs b/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsParameterFilter.cs index 1e3c7dee15..6eb17fa94d 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsParameterFilter.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsParameterFilter.cs @@ -67,7 +67,7 @@ private void ApplyParamTags(OpenApiParameter parameter, ParameterFilterContext c var example = paramNode.GetAttribute("example", ""); if (string.IsNullOrEmpty(example)) return; - parameter.Example = XmlCommentsExampleHelper.Create(context.SchemaRepository, parameter.Schema, example.ToString()); + parameter.Example = XmlCommentsExampleHelper.Create(context.SchemaRepository, parameter.Schema, example); } } } diff --git a/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsExampleHelperTests.cs b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsExampleHelperTests.cs index 50d9b59bad..f932f9f8cb 100644 --- a/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsExampleHelperTests.cs +++ b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsExampleHelperTests.cs @@ -50,5 +50,15 @@ public void Create_ReturnsNull_When_TypeString_and_ValueNull() Assert.Equal(AnyType.Null, ((OpenApiNull)example).AnyType); } + + [Fact] + public void Create_AllowsSchemaToBeNull() + { + OpenApiSchema schema = null; + + IOpenApiAny example = XmlCommentsExampleHelper.Create(schemaRepository, schema, "[]"); + + Assert.Empty((OpenApiArray)example); + } } } From 8186b21cd0be55d074129b9abb69660e4d35fa60 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 5 May 2024 15:50:06 +0200 Subject: [PATCH 3/6] Adapt suggestion from code review - use static string.Equals - assert for not null and correct type --- .../XmlComments/XmlCommentsExampleHelper.cs | 2 +- .../XmlComments/XmlCommentsExampleHelperTests.cs | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsExampleHelper.cs b/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsExampleHelper.cs index 185953afdb..8795bde425 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsExampleHelper.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsExampleHelper.cs @@ -13,7 +13,7 @@ public static IOpenApiAny Create( { var isStringType = (schema?.ResolveType(schemaRepository) == "string") && - !exampleString.Equals("null"); + !string.Equals(exampleString, "null"); var exampleAsJson = isStringType ? JsonSerializer.Serialize(exampleString) diff --git a/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsExampleHelperTests.cs b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsExampleHelperTests.cs index f932f9f8cb..0985a9e0b3 100644 --- a/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsExampleHelperTests.cs +++ b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsExampleHelperTests.cs @@ -11,7 +11,7 @@ public class XmlCommentsExampleHelperTests [Fact] public void Create_BuildsOpenApiArrayJson__When_NotStringTypeAndDataIsArray() { - OpenApiSchema schema = new OpenApiSchema(); + var schema = new OpenApiSchema(); IOpenApiAny example = XmlCommentsExampleHelper.Create( schemaRepository, @@ -19,6 +19,8 @@ public void Create_BuildsOpenApiArrayJson__When_NotStringTypeAndDataIsArray() "[\"one\",\"two\",\"three\"]"); + Assert.NotNull(example); + Assert.IsType(example); var output = (OpenApiArray)example; Assert.Equal(3, output.Count); Assert.Equal("one", ((OpenApiString)output[0]).Value); @@ -36,6 +38,8 @@ public void Create_BuildsOpenApiString_When_TypeString() IOpenApiAny example = XmlCommentsExampleHelper.Create( schemaRepository, schema, exampleString); + Assert.NotNull(example); + Assert.IsType(example); Assert.Equal(((OpenApiString)example).Value, exampleString); } @@ -48,6 +52,8 @@ public void Create_ReturnsNull_When_TypeString_and_ValueNull() IOpenApiAny example = XmlCommentsExampleHelper.Create( schemaRepository, schema, "null"); + Assert.NotNull(example); + Assert.IsType(example); Assert.Equal(AnyType.Null, ((OpenApiNull)example).AnyType); } @@ -58,6 +64,8 @@ public void Create_AllowsSchemaToBeNull() IOpenApiAny example = XmlCommentsExampleHelper.Create(schemaRepository, schema, "[]"); + Assert.NotNull(example); + Assert.IsType(example); Assert.Empty((OpenApiArray)example); } } From 6e225b94b2642895a256d8aa751339ac8907d214 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 5 May 2024 16:10:58 +0200 Subject: [PATCH 4/6] Make XmlCommentsExampleHelper internal --- .../XmlComments/XmlCommentsExampleHelper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsExampleHelper.cs b/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsExampleHelper.cs index 8795bde425..40a2271723 100644 --- a/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsExampleHelper.cs +++ b/src/Swashbuckle.AspNetCore.SwaggerGen/XmlComments/XmlCommentsExampleHelper.cs @@ -4,7 +4,7 @@ namespace Swashbuckle.AspNetCore.SwaggerGen { - public static class XmlCommentsExampleHelper + internal static class XmlCommentsExampleHelper { public static IOpenApiAny Create( SchemaRepository schemaRepository, From 9020e18f296d9b169233a424096ecb53f9652b23 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 5 May 2024 16:45:18 +0200 Subject: [PATCH 5/6] Update asserts --- .../XmlCommentsExampleHelperTests.cs | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsExampleHelperTests.cs b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsExampleHelperTests.cs index 0985a9e0b3..ed447b0297 100644 --- a/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsExampleHelperTests.cs +++ b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsExampleHelperTests.cs @@ -20,12 +20,15 @@ public void Create_BuildsOpenApiArrayJson__When_NotStringTypeAndDataIsArray() Assert.NotNull(example); - Assert.IsType(example); - var output = (OpenApiArray)example; - Assert.Equal(3, output.Count); - Assert.Equal("one", ((OpenApiString)output[0]).Value); - Assert.Equal("two", ((OpenApiString)output[1]).Value); - Assert.Equal("three", ((OpenApiString)output[2]).Value); + var actual = Assert.IsType(example); + Assert.Equal(3, actual.Count); + + var item1 = Assert.IsType(actual[0]); + var item2 = Assert.IsType(actual[1]); + var item3 = Assert.IsType(actual[2]); + Assert.Equal("one", item1.Value); + Assert.Equal("two", item2.Value); + Assert.Equal("three", item3.Value); } [Fact] @@ -39,8 +42,8 @@ public void Create_BuildsOpenApiString_When_TypeString() schemaRepository, schema, exampleString); Assert.NotNull(example); - Assert.IsType(example); - Assert.Equal(((OpenApiString)example).Value, exampleString); + var actual = Assert.IsType(example); + Assert.Equal(actual.Value, exampleString); } [Fact] @@ -53,8 +56,8 @@ public void Create_ReturnsNull_When_TypeString_and_ValueNull() schemaRepository, schema, "null"); Assert.NotNull(example); - Assert.IsType(example); - Assert.Equal(AnyType.Null, ((OpenApiNull)example).AnyType); + var actual = Assert.IsType(example); + Assert.Equal(AnyType.Null, actual.AnyType); } [Fact] @@ -65,8 +68,8 @@ public void Create_AllowsSchemaToBeNull() IOpenApiAny example = XmlCommentsExampleHelper.Create(schemaRepository, schema, "[]"); Assert.NotNull(example); - Assert.IsType(example); - Assert.Empty((OpenApiArray)example); + var actual = Assert.IsType(example); + Assert.Empty(actual); } } } From 7989435cb9bf000b3a88abda4a855342de66dfaf Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 5 May 2024 16:47:36 +0200 Subject: [PATCH 6/6] PR suggestions, adapting asserts --- .../XmlComments/XmlCommentsExampleHelperTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsExampleHelperTests.cs b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsExampleHelperTests.cs index ed447b0297..a9b7cfd6b6 100644 --- a/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsExampleHelperTests.cs +++ b/test/Swashbuckle.AspNetCore.SwaggerGen.Test/XmlComments/XmlCommentsExampleHelperTests.cs @@ -18,7 +18,6 @@ public void Create_BuildsOpenApiArrayJson__When_NotStringTypeAndDataIsArray() schema, "[\"one\",\"two\",\"three\"]"); - Assert.NotNull(example); var actual = Assert.IsType(example); Assert.Equal(3, actual.Count);