From ced0015d04920cef3e24bc74cb36b3fb4cfc20ab Mon Sep 17 00:00:00 2001 From: Pradeep Ramola Date: Sun, 19 Jul 2026 01:13:05 -0400 Subject: [PATCH 1/3] Use schema examples for XML comment examples --- .../gen/XmlCommentGenerator.Emitter.cs | 4 +-- .../AdditionalTextsTests.Schemas.cs | 28 +++++++-------- .../SchemaTests.cs | 34 +++++++++---------- ...ApiXmlCommentSupport.generated.verified.cs | 6 ++-- ...ApiXmlCommentSupport.generated.verified.cs | 6 ++-- ...ApiXmlCommentSupport.generated.verified.cs | 6 ++-- ...ApiXmlCommentSupport.generated.verified.cs | 6 ++-- ...ApiXmlCommentSupport.generated.verified.cs | 6 ++-- ...ApiXmlCommentSupport.generated.verified.cs | 6 ++-- ...ApiXmlCommentSupport.generated.verified.cs | 6 ++-- ...ApiXmlCommentSupport.generated.verified.cs | 6 ++-- ...ApiXmlCommentSupport.generated.verified.cs | 6 ++-- ...ApiXmlCommentSupport.generated.verified.cs | 6 ++-- ...nApiDocument_documentName=xml.verified.txt | 28 +++++++++++---- ...nApiDocument_documentName=xml.verified.txt | 28 +++++++++++---- ...nApiDocument_documentName=xml.verified.txt | 28 +++++++++++---- 16 files changed, 126 insertions(+), 84 deletions(-) diff --git a/src/OpenApi/gen/XmlCommentGenerator.Emitter.cs b/src/OpenApi/gen/XmlCommentGenerator.Emitter.cs index 82864654e936..d4399e954989 100644 --- a/src/OpenApi/gen/XmlCommentGenerator.Emitter.cs +++ b/src/OpenApi/gen/XmlCommentGenerator.Emitter.cs @@ -534,7 +534,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext schema.Description = typeComment.Summary; if (typeComment.Examples?.FirstOrDefault() is { } jsonString) { - schema.Example = jsonString.Parse(); + schema.Examples = [jsonString.Parse()]; } } @@ -560,7 +560,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext schema.Description = description; if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) { - schema.Example = jsonString.Parse(); + schema.Examples = [jsonString.Parse()]; } } else diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/AdditionalTextsTests.Schemas.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/AdditionalTextsTests.Schemas.cs index d349f172b24e..531da68f5979 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/AdditionalTextsTests.Schemas.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/AdditionalTextsTests.Schemas.cs @@ -220,46 +220,46 @@ await SnapshotTestHelper.VerifyOpenApi(compilation, additionalAssemblies, docume path = document.Paths["/type-with-examples"].Operations[HttpMethod.Post]; var typeWithExamples = path.RequestBody.Content["application/json"].Schema; - var booleanTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["booleanType"].Example); + var booleanTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["booleanType"].Examples[0]); Assert.True(booleanTypeExample.GetValue()); - var integerTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["integerType"].Example); + var integerTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["integerType"].Examples[0]); Assert.Equal(42, integerTypeExample.GetValue()); - var longTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["longType"].Example); + var longTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["longType"].Examples[0]); Assert.Equal(1234567890123456789, longTypeExample.GetValue()); - var doubleTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["doubleType"].Example); + var doubleTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["doubleType"].Examples[0]); Assert.Equal(3.14, doubleTypeExample.GetValue()); - var floatTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["floatType"].Example); + var floatTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["floatType"].Examples[0]); Assert.Equal(3.14f, floatTypeExample.GetValue()); - var dateTimeTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["dateTimeType"].Example); + var dateTimeTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["dateTimeType"].Examples[0]); Assert.Equal(new DateTime(2022, 01, 01), dateTimeTypeExample.GetValue()); - var dateOnlyTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["dateOnlyType"].Example); + var dateOnlyTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["dateOnlyType"].Examples[0]); Assert.Equal("2022-01-01", dateOnlyTypeExample.GetValue()); - var stringTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["stringType"].Example); + var stringTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["stringType"].Examples[0]); Assert.Equal("Hello, World!", stringTypeExample.GetValue()); - var guidTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["guidType"].Example); + var guidTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["guidType"].Examples[0]); Assert.Equal("2d8f1eac-b5c6-4e29-8c62-4d9d75ef3d3d", guidTypeExample.GetValue()); - var byteTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["byteType"].Example); + var byteTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["byteType"].Examples[0]); Assert.Equal(255, byteTypeExample.GetValue()); - var timeOnlyTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["timeOnlyType"].Example); + var timeOnlyTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["timeOnlyType"].Examples[0]); Assert.Equal("12:30:45", timeOnlyTypeExample.GetValue()); - var timeSpanTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["timeSpanType"].Example); + var timeSpanTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["timeSpanType"].Examples[0]); Assert.Equal("P3DT4H5M", timeSpanTypeExample.GetValue()); - var decimalTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["decimalType"].Example); + var decimalTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["decimalType"].Examples[0]); Assert.Equal(3.14159265359m, decimalTypeExample.GetValue()); - var uriTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["uriType"].Example); + var uriTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["uriType"].Examples[0]); Assert.Equal("https://example.com", uriTypeExample.GetValue()); }); } diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/SchemaTests.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/SchemaTests.cs index 9fcd24ca2dec..73ee3e4db231 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/SchemaTests.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/SchemaTests.cs @@ -217,46 +217,46 @@ await SnapshotTestHelper.VerifyOpenApi(compilation, document => path = document.Paths["/type-with-examples"].Operations[HttpMethod.Post]; var typeWithExamples = path.RequestBody.Content["application/json"].Schema; - var booleanTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["booleanType"].Example); + var booleanTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["booleanType"].Examples[0]); Assert.True(booleanTypeExample.GetValue()); - var integerTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["integerType"].Example); + var integerTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["integerType"].Examples[0]); Assert.Equal(42, integerTypeExample.GetValue()); - var longTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["longType"].Example); + var longTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["longType"].Examples[0]); Assert.Equal(1234567890123456789, longTypeExample.GetValue()); - var doubleTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["doubleType"].Example); + var doubleTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["doubleType"].Examples[0]); Assert.Equal(3.14, doubleTypeExample.GetValue()); - var floatTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["floatType"].Example); + var floatTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["floatType"].Examples[0]); Assert.Equal(3.14f, floatTypeExample.GetValue()); - var dateTimeTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["dateTimeType"].Example); + var dateTimeTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["dateTimeType"].Examples[0]); Assert.Equal(new DateTime(2022, 01, 01), dateTimeTypeExample.GetValue()); - var dateOnlyTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["dateOnlyType"].Example); + var dateOnlyTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["dateOnlyType"].Examples[0]); Assert.Equal("2022-01-01", dateOnlyTypeExample.GetValue()); - var stringTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["stringType"].Example); + var stringTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["stringType"].Examples[0]); Assert.Equal("Hello, World!", stringTypeExample.GetValue()); - var guidTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["guidType"].Example); + var guidTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["guidType"].Examples[0]); Assert.Equal("2d8f1eac-b5c6-4e29-8c62-4d9d75ef3d3d", guidTypeExample.GetValue()); - var byteTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["byteType"].Example); + var byteTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["byteType"].Examples[0]); Assert.Equal(255, byteTypeExample.GetValue()); - var timeOnlyTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["timeOnlyType"].Example); + var timeOnlyTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["timeOnlyType"].Examples[0]); Assert.Equal("12:30:45", timeOnlyTypeExample.GetValue()); - var timeSpanTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["timeSpanType"].Example); + var timeSpanTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["timeSpanType"].Examples[0]); Assert.Equal("P3DT4H5M", timeSpanTypeExample.GetValue()); - var decimalTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["decimalType"].Example); + var decimalTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["decimalType"].Examples[0]); Assert.Equal(3.14159265359m, decimalTypeExample.GetValue()); - var uriTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["uriType"].Example); + var uriTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["uriType"].Examples[0]); Assert.Equal("https://example.com", uriTypeExample.GetValue()); path = document.Paths["/user"].Operations[HttpMethod.Post]; @@ -386,7 +386,7 @@ await SnapshotTestHelper.VerifyOpenApi(compilation, document => var modelWithSummary = document.Components.Schemas["ModelWithSummary"]; Assert.Equal("Comment on class ModelWithSummary.", modelWithSummary.Description); - Assert.True(JsonNode.DeepEquals(JsonNode.Parse("""{ "street": "ModelWithSummaryClass" }"""), modelWithSummary.Example)); + Assert.True(JsonNode.DeepEquals(JsonNode.Parse("""{ "street": "ModelWithSummaryClass" }"""), modelWithSummary.Examples[0])); var modelWithoutSummary = document.Components.Schemas["ModelWithoutSummary"]; Assert.Null(modelWithoutSummary.Description); @@ -415,11 +415,11 @@ await SnapshotTestHelper.VerifyOpenApi(compilation, document => var modelInline1Prop = Assert.IsType(rootModelSchema.Properties["modelInline1"]); Assert.Equal("Comment on property ModelInline1.", modelInline1Prop.Description); - Assert.True(JsonNode.DeepEquals(JsonNode.Parse("""{ "street": "ModelInline1Prop" }"""), modelInline1Prop.Example)); + Assert.True(JsonNode.DeepEquals(JsonNode.Parse("""{ "street": "ModelInline1Prop" }"""), modelInline1Prop.Examples[0])); var modelInline2Prop = Assert.IsType(rootModelSchema.Properties["modelInline2"]); Assert.Equal("Comment on property ModelInline2.", modelInline2Prop.Description); - Assert.True(JsonNode.DeepEquals(JsonNode.Parse("""{ "street": "ModelInline2Prop" }"""), modelInline2Prop.Example)); + Assert.True(JsonNode.DeepEquals(JsonNode.Parse("""{ "street": "ModelInline2Prop" }"""), modelInline2Prop.Examples[0])); }); } } diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AddOpenApiTests.CanInterceptAddOpenApi#OpenApiXmlCommentSupport.generated.verified.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AddOpenApiTests.CanInterceptAddOpenApi#OpenApiXmlCommentSupport.generated.verified.cs index 6c44a0094278..f1a6b2648a3c 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AddOpenApiTests.CanInterceptAddOpenApi#OpenApiXmlCommentSupport.generated.verified.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AddOpenApiTests.CanInterceptAddOpenApi#OpenApiXmlCommentSupport.generated.verified.cs @@ -1,4 +1,4 @@ -//HintName: OpenApiXmlCommentSupport.generated.cs +//HintName: OpenApiXmlCommentSupport.generated.cs //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -516,7 +516,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext schema.Description = typeComment.Summary; if (typeComment.Examples?.FirstOrDefault() is { } jsonString) { - schema.Example = jsonString.Parse(); + schema.Examples = [jsonString.Parse()]; } } @@ -542,7 +542,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext schema.Description = description; if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) { - schema.Example = jsonString.Parse(); + schema.Examples = [jsonString.Parse()]; } } else diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AdditionalTextsTests.CanHandleXmlForSchemasInAdditionalTexts#OpenApiXmlCommentSupport.generated.verified.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AdditionalTextsTests.CanHandleXmlForSchemasInAdditionalTexts#OpenApiXmlCommentSupport.generated.verified.cs index 0e41890976c0..4f1cd023800f 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AdditionalTextsTests.CanHandleXmlForSchemasInAdditionalTexts#OpenApiXmlCommentSupport.generated.verified.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AdditionalTextsTests.CanHandleXmlForSchemasInAdditionalTexts#OpenApiXmlCommentSupport.generated.verified.cs @@ -1,4 +1,4 @@ -//HintName: OpenApiXmlCommentSupport.generated.cs +//HintName: OpenApiXmlCommentSupport.generated.cs //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -545,7 +545,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext schema.Description = typeComment.Summary; if (typeComment.Examples?.FirstOrDefault() is { } jsonString) { - schema.Example = jsonString.Parse(); + schema.Examples = [jsonString.Parse()]; } } @@ -571,7 +571,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext schema.Description = description; if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) { - schema.Example = jsonString.Parse(); + schema.Examples = [jsonString.Parse()]; } } else diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/CompletenessTests.SupportsAllXmlTagsOnSchemas#OpenApiXmlCommentSupport.generated.verified.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/CompletenessTests.SupportsAllXmlTagsOnSchemas#OpenApiXmlCommentSupport.generated.verified.cs index 4a0aaf7895bf..1f4bd35d84b4 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/CompletenessTests.SupportsAllXmlTagsOnSchemas#OpenApiXmlCommentSupport.generated.verified.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/CompletenessTests.SupportsAllXmlTagsOnSchemas#OpenApiXmlCommentSupport.generated.verified.cs @@ -1,4 +1,4 @@ -//HintName: OpenApiXmlCommentSupport.generated.cs +//HintName: OpenApiXmlCommentSupport.generated.cs //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -643,7 +643,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext schema.Description = typeComment.Summary; if (typeComment.Examples?.FirstOrDefault() is { } jsonString) { - schema.Example = jsonString.Parse(); + schema.Examples = [jsonString.Parse()]; } } @@ -669,7 +669,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext schema.Description = description; if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) { - schema.Example = jsonString.Parse(); + schema.Examples = [jsonString.Parse()]; } } else diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsRouteParametersFromControllers#OpenApiXmlCommentSupport.generated.verified.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsRouteParametersFromControllers#OpenApiXmlCommentSupport.generated.verified.cs index e569ddc2f4a8..676c864e3e59 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsRouteParametersFromControllers#OpenApiXmlCommentSupport.generated.verified.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsRouteParametersFromControllers#OpenApiXmlCommentSupport.generated.verified.cs @@ -1,4 +1,4 @@ -//HintName: OpenApiXmlCommentSupport.generated.cs +//HintName: OpenApiXmlCommentSupport.generated.cs //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -517,7 +517,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext schema.Description = typeComment.Summary; if (typeComment.Examples?.FirstOrDefault() is { } jsonString) { - schema.Example = jsonString.Parse(); + schema.Examples = [jsonString.Parse()]; } } @@ -543,7 +543,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext schema.Description = description; if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) { - schema.Example = jsonString.Parse(); + schema.Examples = [jsonString.Parse()]; } } else diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsXmlCommentsOnOperationsFromControllers#OpenApiXmlCommentSupport.generated.verified.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsXmlCommentsOnOperationsFromControllers#OpenApiXmlCommentSupport.generated.verified.cs index 6ac0fcb221a9..3aaceaae2227 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsXmlCommentsOnOperationsFromControllers#OpenApiXmlCommentSupport.generated.verified.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsXmlCommentsOnOperationsFromControllers#OpenApiXmlCommentSupport.generated.verified.cs @@ -1,4 +1,4 @@ -//HintName: OpenApiXmlCommentSupport.generated.cs +//HintName: OpenApiXmlCommentSupport.generated.cs //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -520,7 +520,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext schema.Description = typeComment.Summary; if (typeComment.Examples?.FirstOrDefault() is { } jsonString) { - schema.Example = jsonString.Parse(); + schema.Examples = [jsonString.Parse()]; } } @@ -546,7 +546,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext schema.Description = description; if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) { - schema.Example = jsonString.Parse(); + schema.Examples = [jsonString.Parse()]; } } else diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsXmlCommentsOnOperationsFromMinimalApis#OpenApiXmlCommentSupport.generated.verified.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsXmlCommentsOnOperationsFromMinimalApis#OpenApiXmlCommentSupport.generated.verified.cs index 85d5e91dd378..7b276a438fe2 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsXmlCommentsOnOperationsFromMinimalApis#OpenApiXmlCommentSupport.generated.verified.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsXmlCommentsOnOperationsFromMinimalApis#OpenApiXmlCommentSupport.generated.verified.cs @@ -1,4 +1,4 @@ -//HintName: OpenApiXmlCommentSupport.generated.cs +//HintName: OpenApiXmlCommentSupport.generated.cs //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -564,7 +564,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext schema.Description = typeComment.Summary; if (typeComment.Examples?.FirstOrDefault() is { } jsonString) { - schema.Example = jsonString.Parse(); + schema.Examples = [jsonString.Parse()]; } } @@ -590,7 +590,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext schema.Description = description; if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) { - schema.Example = jsonString.Parse(); + schema.Examples = [jsonString.Parse()]; } } else diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/SchemaTests.SupportsXmlCommentsOnSchemas#OpenApiXmlCommentSupport.generated.verified.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/SchemaTests.SupportsXmlCommentsOnSchemas#OpenApiXmlCommentSupport.generated.verified.cs index 9f6a292f13bb..888f402b3abf 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/SchemaTests.SupportsXmlCommentsOnSchemas#OpenApiXmlCommentSupport.generated.verified.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/SchemaTests.SupportsXmlCommentsOnSchemas#OpenApiXmlCommentSupport.generated.verified.cs @@ -1,4 +1,4 @@ -//HintName: OpenApiXmlCommentSupport.generated.cs +//HintName: OpenApiXmlCommentSupport.generated.cs //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -546,7 +546,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext schema.Description = typeComment.Summary; if (typeComment.Examples?.FirstOrDefault() is { } jsonString) { - schema.Example = jsonString.Parse(); + schema.Examples = [jsonString.Parse()]; } } @@ -572,7 +572,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext schema.Description = description; if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) { - schema.Example = jsonString.Parse(); + schema.Examples = [jsonString.Parse()]; } } else diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/SchemaTests.XmlCommentsOnPropertiesShouldApplyToSchemaReferences#OpenApiXmlCommentSupport.generated.verified.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/SchemaTests.XmlCommentsOnPropertiesShouldApplyToSchemaReferences#OpenApiXmlCommentSupport.generated.verified.cs index be4687040128..df02bd374492 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/SchemaTests.XmlCommentsOnPropertiesShouldApplyToSchemaReferences#OpenApiXmlCommentSupport.generated.verified.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/SchemaTests.XmlCommentsOnPropertiesShouldApplyToSchemaReferences#OpenApiXmlCommentSupport.generated.verified.cs @@ -1,4 +1,4 @@ -//HintName: OpenApiXmlCommentSupport.generated.cs +//HintName: OpenApiXmlCommentSupport.generated.cs //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -525,7 +525,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext schema.Description = typeComment.Summary; if (typeComment.Examples?.FirstOrDefault() is { } jsonString) { - schema.Example = jsonString.Parse(); + schema.Examples = [jsonString.Parse()]; } } @@ -551,7 +551,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext schema.Description = description; if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) { - schema.Example = jsonString.Parse(); + schema.Examples = [jsonString.Parse()]; } } else diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/XmlCommentDocumentationIdTests.CanMergeXmlCommentsWithDifferentDocumentationIdFormats#OpenApiXmlCommentSupport.generated.verified.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/XmlCommentDocumentationIdTests.CanMergeXmlCommentsWithDifferentDocumentationIdFormats#OpenApiXmlCommentSupport.generated.verified.cs index 14e6fc1de407..2c8aa82f552b 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/XmlCommentDocumentationIdTests.CanMergeXmlCommentsWithDifferentDocumentationIdFormats#OpenApiXmlCommentSupport.generated.verified.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/XmlCommentDocumentationIdTests.CanMergeXmlCommentsWithDifferentDocumentationIdFormats#OpenApiXmlCommentSupport.generated.verified.cs @@ -1,4 +1,4 @@ -//HintName: OpenApiXmlCommentSupport.generated.cs +//HintName: OpenApiXmlCommentSupport.generated.cs //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -517,7 +517,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext schema.Description = typeComment.Summary; if (typeComment.Examples?.FirstOrDefault() is { } jsonString) { - schema.Example = jsonString.Parse(); + schema.Examples = [jsonString.Parse()]; } } @@ -543,7 +543,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext schema.Description = description; if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) { - schema.Example = jsonString.Parse(); + schema.Examples = [jsonString.Parse()]; } } else diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/XmlCommentDocumentationIdTests.ShouldNotDuplicateDocumentationIds#OpenApiXmlCommentSupport.generated.verified.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/XmlCommentDocumentationIdTests.ShouldNotDuplicateDocumentationIds#OpenApiXmlCommentSupport.generated.verified.cs index de974c97d313..af3a74d1bf9f 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/XmlCommentDocumentationIdTests.ShouldNotDuplicateDocumentationIds#OpenApiXmlCommentSupport.generated.verified.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/XmlCommentDocumentationIdTests.ShouldNotDuplicateDocumentationIds#OpenApiXmlCommentSupport.generated.verified.cs @@ -1,4 +1,4 @@ -//HintName: OpenApiXmlCommentSupport.generated.cs +//HintName: OpenApiXmlCommentSupport.generated.cs //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -520,7 +520,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext schema.Description = typeComment.Summary; if (typeComment.Examples?.FirstOrDefault() is { } jsonString) { - schema.Example = jsonString.Parse(); + schema.Examples = [jsonString.Parse()]; } } @@ -546,7 +546,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext schema.Description = description; if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) { - schema.Example = jsonString.Parse(); + schema.Examples = [jsonString.Parse()]; } } else diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_0/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=xml.verified.txt b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_0/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=xml.verified.txt index d2b295c23ab6..979db19c3219 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_0/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=xml.verified.txt +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_0/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=xml.verified.txt @@ -350,37 +350,51 @@ "properties": { "booleanType": { "type": "boolean", - "example": true + "examples": [ + true + ] }, "integerType": { "type": "integer", "format": "int32", - "example": 42 + "examples": [ + 42 + ] }, "longType": { "type": "integer", "format": "int64", - "example": 1234567890123456789 + "examples": [ + 1234567890123456789 + ] }, "doubleType": { "type": "number", "format": "double", - "example": 3.14 + "examples": [ + 3.14 + ] }, "floatType": { "type": "number", "format": "float", - "example": 3.14 + "examples": [ + 3.14 + ] }, "dateTimeType": { "type": "string", "format": "date-time", - "example": "2022-01-01T00:00:00Z" + "examples": [ + "2022-01-01T00:00:00Z" + ] }, "dateOnlyType": { "type": "string", "format": "date", - "example": "2022-01-01" + "examples": [ + "2022-01-01" + ] } } } diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_1/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=xml.verified.txt b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_1/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=xml.verified.txt index c2d9ef8c8393..121cfa6fb192 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_1/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=xml.verified.txt +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_1/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=xml.verified.txt @@ -350,37 +350,51 @@ "properties": { "booleanType": { "type": "boolean", - "example": true + "examples": [ + true + ] }, "integerType": { "type": "integer", "format": "int32", - "example": 42 + "examples": [ + 42 + ] }, "longType": { "type": "integer", "format": "int64", - "example": 1234567890123456789 + "examples": [ + 1234567890123456789 + ] }, "doubleType": { "type": "number", "format": "double", - "example": 3.14 + "examples": [ + 3.14 + ] }, "floatType": { "type": "number", "format": "float", - "example": 3.14 + "examples": [ + 3.14 + ] }, "dateTimeType": { "type": "string", "format": "date-time", - "example": "2022-01-01T00:00:00Z" + "examples": [ + "2022-01-01T00:00:00Z" + ] }, "dateOnlyType": { "type": "string", "format": "date", - "example": "2022-01-01" + "examples": [ + "2022-01-01" + ] } } } diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_2/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=xml.verified.txt b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_2/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=xml.verified.txt index 74aff7eb39d0..504c53072d58 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_2/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=xml.verified.txt +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.Tests/Integration/snapshots/OpenApi3_2/OpenApiDocumentIntegrationTests.VerifyOpenApiDocument_documentName=xml.verified.txt @@ -350,37 +350,51 @@ "properties": { "booleanType": { "type": "boolean", - "example": true + "examples": [ + true + ] }, "integerType": { "type": "integer", "format": "int32", - "example": 42 + "examples": [ + 42 + ] }, "longType": { "type": "integer", "format": "int64", - "example": 1234567890123456789 + "examples": [ + 1234567890123456789 + ] }, "doubleType": { "type": "number", "format": "double", - "example": 3.14 + "examples": [ + 3.14 + ] }, "floatType": { "type": "number", "format": "float", - "example": 3.14 + "examples": [ + 3.14 + ] }, "dateTimeType": { "type": "string", "format": "date-time", - "example": "2022-01-01T00:00:00Z" + "examples": [ + "2022-01-01T00:00:00Z" + ] }, "dateOnlyType": { "type": "string", "format": "date", - "example": "2022-01-01" + "examples": [ + "2022-01-01" + ] } } } From f850b7c1e3fe27ac14686e2d3ee3e2411fc1d4bb Mon Sep 17 00:00:00 2001 From: Pradeep Ramola Date: Mon, 20 Jul 2026 03:31:38 -0400 Subject: [PATCH 2/3] Address XML comment schema examples review --- src/OpenApi/gen/XmlCommentGenerator.Emitter.cs | 8 ++++---- .../SchemaTests.cs | 7 +++++++ ...pi#OpenApiXmlCommentSupport.generated.verified.cs | 10 +++++----- ...ts#OpenApiXmlCommentSupport.generated.verified.cs | 10 +++++----- ...as#OpenApiXmlCommentSupport.generated.verified.cs | 10 +++++----- ...rs#OpenApiXmlCommentSupport.generated.verified.cs | 10 +++++----- ...rs#OpenApiXmlCommentSupport.generated.verified.cs | 10 +++++----- ...is#OpenApiXmlCommentSupport.generated.verified.cs | 10 +++++----- ...as#OpenApiXmlCommentSupport.generated.verified.cs | 12 ++++++------ ...es#OpenApiXmlCommentSupport.generated.verified.cs | 12 ++++++------ ...ts#OpenApiXmlCommentSupport.generated.verified.cs | 10 +++++----- ...ds#OpenApiXmlCommentSupport.generated.verified.cs | 10 +++++----- 12 files changed, 63 insertions(+), 56 deletions(-) diff --git a/src/OpenApi/gen/XmlCommentGenerator.Emitter.cs b/src/OpenApi/gen/XmlCommentGenerator.Emitter.cs index d4399e954989..f59288b4800d 100644 --- a/src/OpenApi/gen/XmlCommentGenerator.Emitter.cs +++ b/src/OpenApi/gen/XmlCommentGenerator.Emitter.cs @@ -532,9 +532,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(context.JsonTypeInfo.Type.CreateDocumentationId()), out var typeComment)) { schema.Description = typeComment.Summary; - if (typeComment.Examples?.FirstOrDefault() is { } jsonString) + if (typeComment.Examples is { Count: > 0 } typeExamples) { - schema.Examples = [jsonString.Parse()]; + schema.Examples = typeExamples.ConvertAll(example => example.Parse()!); } } @@ -558,9 +558,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext { // Inlined schema schema.Description = description; - if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) + if (propertyComment.Examples is { Count: > 0 } propertyExamples) { - schema.Examples = [jsonString.Parse()]; + schema.Examples = propertyExamples.ConvertAll(example => example.Parse()!); } } else diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/SchemaTests.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/SchemaTests.cs index 73ee3e4db231..3c2f7e398c6a 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/SchemaTests.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/SchemaTests.cs @@ -138,6 +138,7 @@ public class TypeWithExamples /// 2022-01-01 public DateOnly DateOnlyType { get; set; } /// Hello, World! + /// Goodbye, World! public string StringType { get; set; } /// 2d8f1eac-b5c6-4e29-8c62-4d9d75ef3d3d public Guid GuidType { get; set; } @@ -240,6 +241,8 @@ await SnapshotTestHelper.VerifyOpenApi(compilation, document => var stringTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["stringType"].Examples[0]); Assert.Equal("Hello, World!", stringTypeExample.GetValue()); + var secondStringTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["stringType"].Examples[1]); + Assert.Equal("Goodbye, World!", secondStringTypeExample.GetValue()); var guidTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["guidType"].Examples[0]); Assert.Equal("2d8f1eac-b5c6-4e29-8c62-4d9d75ef3d3d", guidTypeExample.GetValue()); @@ -293,6 +296,9 @@ public async Task XmlCommentsOnPropertiesShouldApplyToSchemaReferences() /// /// { "street": "ModelWithSummaryClass" } /// +/// +/// { "street": "ModelWithSummaryClass2" } +/// public class ModelWithSummary { public string Street { get; set; } @@ -387,6 +393,7 @@ await SnapshotTestHelper.VerifyOpenApi(compilation, document => var modelWithSummary = document.Components.Schemas["ModelWithSummary"]; Assert.Equal("Comment on class ModelWithSummary.", modelWithSummary.Description); Assert.True(JsonNode.DeepEquals(JsonNode.Parse("""{ "street": "ModelWithSummaryClass" }"""), modelWithSummary.Examples[0])); + Assert.True(JsonNode.DeepEquals(JsonNode.Parse("""{ "street": "ModelWithSummaryClass2" }"""), modelWithSummary.Examples[1])); var modelWithoutSummary = document.Components.Schemas["ModelWithoutSummary"]; Assert.Null(modelWithoutSummary.Description); diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AddOpenApiTests.CanInterceptAddOpenApi#OpenApiXmlCommentSupport.generated.verified.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AddOpenApiTests.CanInterceptAddOpenApi#OpenApiXmlCommentSupport.generated.verified.cs index f1a6b2648a3c..ffccd10f73e8 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AddOpenApiTests.CanInterceptAddOpenApi#OpenApiXmlCommentSupport.generated.verified.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AddOpenApiTests.CanInterceptAddOpenApi#OpenApiXmlCommentSupport.generated.verified.cs @@ -1,4 +1,4 @@ -//HintName: OpenApiXmlCommentSupport.generated.cs +//HintName: OpenApiXmlCommentSupport.generated.cs //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -514,9 +514,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(context.JsonTypeInfo.Type.CreateDocumentationId()), out var typeComment)) { schema.Description = typeComment.Summary; - if (typeComment.Examples?.FirstOrDefault() is { } jsonString) + if (typeComment.Examples is { Count: > 0 } typeExamples) { - schema.Examples = [jsonString.Parse()]; + schema.Examples = typeExamples.ConvertAll(example => example.Parse()!); } } @@ -540,9 +540,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext { // Inlined schema schema.Description = description; - if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) + if (propertyComment.Examples is { Count: > 0 } propertyExamples) { - schema.Examples = [jsonString.Parse()]; + schema.Examples = propertyExamples.ConvertAll(example => example.Parse()!); } } else diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AdditionalTextsTests.CanHandleXmlForSchemasInAdditionalTexts#OpenApiXmlCommentSupport.generated.verified.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AdditionalTextsTests.CanHandleXmlForSchemasInAdditionalTexts#OpenApiXmlCommentSupport.generated.verified.cs index 4f1cd023800f..a68619804ccf 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AdditionalTextsTests.CanHandleXmlForSchemasInAdditionalTexts#OpenApiXmlCommentSupport.generated.verified.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AdditionalTextsTests.CanHandleXmlForSchemasInAdditionalTexts#OpenApiXmlCommentSupport.generated.verified.cs @@ -1,4 +1,4 @@ -//HintName: OpenApiXmlCommentSupport.generated.cs +//HintName: OpenApiXmlCommentSupport.generated.cs //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -543,9 +543,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(context.JsonTypeInfo.Type.CreateDocumentationId()), out var typeComment)) { schema.Description = typeComment.Summary; - if (typeComment.Examples?.FirstOrDefault() is { } jsonString) + if (typeComment.Examples is { Count: > 0 } typeExamples) { - schema.Examples = [jsonString.Parse()]; + schema.Examples = typeExamples.ConvertAll(example => example.Parse()!); } } @@ -569,9 +569,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext { // Inlined schema schema.Description = description; - if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) + if (propertyComment.Examples is { Count: > 0 } propertyExamples) { - schema.Examples = [jsonString.Parse()]; + schema.Examples = propertyExamples.ConvertAll(example => example.Parse()!); } } else diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/CompletenessTests.SupportsAllXmlTagsOnSchemas#OpenApiXmlCommentSupport.generated.verified.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/CompletenessTests.SupportsAllXmlTagsOnSchemas#OpenApiXmlCommentSupport.generated.verified.cs index 1f4bd35d84b4..113cb0f3c6a2 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/CompletenessTests.SupportsAllXmlTagsOnSchemas#OpenApiXmlCommentSupport.generated.verified.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/CompletenessTests.SupportsAllXmlTagsOnSchemas#OpenApiXmlCommentSupport.generated.verified.cs @@ -1,4 +1,4 @@ -//HintName: OpenApiXmlCommentSupport.generated.cs +//HintName: OpenApiXmlCommentSupport.generated.cs //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -641,9 +641,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(context.JsonTypeInfo.Type.CreateDocumentationId()), out var typeComment)) { schema.Description = typeComment.Summary; - if (typeComment.Examples?.FirstOrDefault() is { } jsonString) + if (typeComment.Examples is { Count: > 0 } typeExamples) { - schema.Examples = [jsonString.Parse()]; + schema.Examples = typeExamples.ConvertAll(example => example.Parse()!); } } @@ -667,9 +667,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext { // Inlined schema schema.Description = description; - if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) + if (propertyComment.Examples is { Count: > 0 } propertyExamples) { - schema.Examples = [jsonString.Parse()]; + schema.Examples = propertyExamples.ConvertAll(example => example.Parse()!); } } else diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsRouteParametersFromControllers#OpenApiXmlCommentSupport.generated.verified.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsRouteParametersFromControllers#OpenApiXmlCommentSupport.generated.verified.cs index 676c864e3e59..1a1fe569364e 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsRouteParametersFromControllers#OpenApiXmlCommentSupport.generated.verified.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsRouteParametersFromControllers#OpenApiXmlCommentSupport.generated.verified.cs @@ -1,4 +1,4 @@ -//HintName: OpenApiXmlCommentSupport.generated.cs +//HintName: OpenApiXmlCommentSupport.generated.cs //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -515,9 +515,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(context.JsonTypeInfo.Type.CreateDocumentationId()), out var typeComment)) { schema.Description = typeComment.Summary; - if (typeComment.Examples?.FirstOrDefault() is { } jsonString) + if (typeComment.Examples is { Count: > 0 } typeExamples) { - schema.Examples = [jsonString.Parse()]; + schema.Examples = typeExamples.ConvertAll(example => example.Parse()!); } } @@ -541,9 +541,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext { // Inlined schema schema.Description = description; - if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) + if (propertyComment.Examples is { Count: > 0 } propertyExamples) { - schema.Examples = [jsonString.Parse()]; + schema.Examples = propertyExamples.ConvertAll(example => example.Parse()!); } } else diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsXmlCommentsOnOperationsFromControllers#OpenApiXmlCommentSupport.generated.verified.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsXmlCommentsOnOperationsFromControllers#OpenApiXmlCommentSupport.generated.verified.cs index 3aaceaae2227..637e2e736f68 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsXmlCommentsOnOperationsFromControllers#OpenApiXmlCommentSupport.generated.verified.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsXmlCommentsOnOperationsFromControllers#OpenApiXmlCommentSupport.generated.verified.cs @@ -1,4 +1,4 @@ -//HintName: OpenApiXmlCommentSupport.generated.cs +//HintName: OpenApiXmlCommentSupport.generated.cs //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -518,9 +518,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(context.JsonTypeInfo.Type.CreateDocumentationId()), out var typeComment)) { schema.Description = typeComment.Summary; - if (typeComment.Examples?.FirstOrDefault() is { } jsonString) + if (typeComment.Examples is { Count: > 0 } typeExamples) { - schema.Examples = [jsonString.Parse()]; + schema.Examples = typeExamples.ConvertAll(example => example.Parse()!); } } @@ -544,9 +544,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext { // Inlined schema schema.Description = description; - if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) + if (propertyComment.Examples is { Count: > 0 } propertyExamples) { - schema.Examples = [jsonString.Parse()]; + schema.Examples = propertyExamples.ConvertAll(example => example.Parse()!); } } else diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsXmlCommentsOnOperationsFromMinimalApis#OpenApiXmlCommentSupport.generated.verified.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsXmlCommentsOnOperationsFromMinimalApis#OpenApiXmlCommentSupport.generated.verified.cs index 7b276a438fe2..8840cf796668 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsXmlCommentsOnOperationsFromMinimalApis#OpenApiXmlCommentSupport.generated.verified.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsXmlCommentsOnOperationsFromMinimalApis#OpenApiXmlCommentSupport.generated.verified.cs @@ -1,4 +1,4 @@ -//HintName: OpenApiXmlCommentSupport.generated.cs +//HintName: OpenApiXmlCommentSupport.generated.cs //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -562,9 +562,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(context.JsonTypeInfo.Type.CreateDocumentationId()), out var typeComment)) { schema.Description = typeComment.Summary; - if (typeComment.Examples?.FirstOrDefault() is { } jsonString) + if (typeComment.Examples is { Count: > 0 } typeExamples) { - schema.Examples = [jsonString.Parse()]; + schema.Examples = typeExamples.ConvertAll(example => example.Parse()!); } } @@ -588,9 +588,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext { // Inlined schema schema.Description = description; - if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) + if (propertyComment.Examples is { Count: > 0 } propertyExamples) { - schema.Examples = [jsonString.Parse()]; + schema.Examples = propertyExamples.ConvertAll(example => example.Parse()!); } } else diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/SchemaTests.SupportsXmlCommentsOnSchemas#OpenApiXmlCommentSupport.generated.verified.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/SchemaTests.SupportsXmlCommentsOnSchemas#OpenApiXmlCommentSupport.generated.verified.cs index 888f402b3abf..b7d87be6829a 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/SchemaTests.SupportsXmlCommentsOnSchemas#OpenApiXmlCommentSupport.generated.verified.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/SchemaTests.SupportsXmlCommentsOnSchemas#OpenApiXmlCommentSupport.generated.verified.cs @@ -1,4 +1,4 @@ -//HintName: OpenApiXmlCommentSupport.generated.cs +//HintName: OpenApiXmlCommentSupport.generated.cs //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -90,7 +90,7 @@ private static Dictionary GenerateCacheEntries() cache.Add(@"P:TypeWithExamples.FloatType", new XmlComment(null, null, null, null, null, false, [@"3.14"], null, null)); cache.Add(@"P:TypeWithExamples.DateTimeType", new XmlComment(null, null, null, null, null, false, [@"2022-01-01T00:00:00Z"], null, null)); cache.Add(@"P:TypeWithExamples.DateOnlyType", new XmlComment(null, null, null, null, null, false, [@"2022-01-01"], null, null)); - cache.Add(@"P:TypeWithExamples.StringType", new XmlComment(null, null, null, null, null, false, [@"Hello, World!"], null, null)); + cache.Add(@"P:TypeWithExamples.StringType", new XmlComment(null, null, null, null, null, false, [@"Hello, World!", @"Goodbye, World!"], null, null)); cache.Add(@"P:TypeWithExamples.GuidType", new XmlComment(null, null, null, null, null, false, [@"2d8f1eac-b5c6-4e29-8c62-4d9d75ef3d3d"], null, null)); cache.Add(@"P:TypeWithExamples.TimeOnlyType", new XmlComment(null, null, null, null, null, false, [@"12:30:45"], null, null)); cache.Add(@"P:TypeWithExamples.TimeSpanType", new XmlComment(null, null, null, null, null, false, [@"P3DT4H5M"], null, null)); @@ -544,9 +544,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(context.JsonTypeInfo.Type.CreateDocumentationId()), out var typeComment)) { schema.Description = typeComment.Summary; - if (typeComment.Examples?.FirstOrDefault() is { } jsonString) + if (typeComment.Examples is { Count: > 0 } typeExamples) { - schema.Examples = [jsonString.Parse()]; + schema.Examples = typeExamples.ConvertAll(example => example.Parse()!); } } @@ -570,9 +570,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext { // Inlined schema schema.Description = description; - if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) + if (propertyComment.Examples is { Count: > 0 } propertyExamples) { - schema.Examples = [jsonString.Parse()]; + schema.Examples = propertyExamples.ConvertAll(example => example.Parse()!); } } else diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/SchemaTests.XmlCommentsOnPropertiesShouldApplyToSchemaReferences#OpenApiXmlCommentSupport.generated.verified.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/SchemaTests.XmlCommentsOnPropertiesShouldApplyToSchemaReferences#OpenApiXmlCommentSupport.generated.verified.cs index df02bd374492..d299f6116473 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/SchemaTests.XmlCommentsOnPropertiesShouldApplyToSchemaReferences#OpenApiXmlCommentSupport.generated.verified.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/SchemaTests.XmlCommentsOnPropertiesShouldApplyToSchemaReferences#OpenApiXmlCommentSupport.generated.verified.cs @@ -1,4 +1,4 @@ -//HintName: OpenApiXmlCommentSupport.generated.cs +//HintName: OpenApiXmlCommentSupport.generated.cs //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -71,7 +71,7 @@ private static Dictionary GenerateCacheEntries() { var cache = new Dictionary(); - cache.Add(@"T:ModelWithSummary", new XmlComment(@"Comment on class ModelWithSummary.", null, null, null, null, false, [@"{ ""street"": ""ModelWithSummaryClass"" }"], null, null)); + cache.Add(@"T:ModelWithSummary", new XmlComment(@"Comment on class ModelWithSummary.", null, null, null, null, false, [@"{ ""street"": ""ModelWithSummaryClass"" }", @"{ ""street"": ""ModelWithSummaryClass2"" }"], null, null)); cache.Add(@"T:ModelInline", new XmlComment(@"Comment on class ModelInline.", null, null, null, null, false, [@"{ ""street"": ""ModelInlineClass"" }"], null, null)); cache.Add(@"T:RootModel", new XmlComment(@"Comment on class RootModel.", null, null, null, null, false, [@"{ }"], null, null)); cache.Add(@"P:RootModel.ModelWithSummary1", new XmlComment(@"Comment on property ModelWithSummary1.", null, null, null, null, false, [@"{ ""street"": ""ModelWithSummary1Prop"" }"], null, null)); @@ -523,9 +523,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(context.JsonTypeInfo.Type.CreateDocumentationId()), out var typeComment)) { schema.Description = typeComment.Summary; - if (typeComment.Examples?.FirstOrDefault() is { } jsonString) + if (typeComment.Examples is { Count: > 0 } typeExamples) { - schema.Examples = [jsonString.Parse()]; + schema.Examples = typeExamples.ConvertAll(example => example.Parse()!); } } @@ -549,9 +549,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext { // Inlined schema schema.Description = description; - if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) + if (propertyComment.Examples is { Count: > 0 } propertyExamples) { - schema.Examples = [jsonString.Parse()]; + schema.Examples = propertyExamples.ConvertAll(example => example.Parse()!); } } else diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/XmlCommentDocumentationIdTests.CanMergeXmlCommentsWithDifferentDocumentationIdFormats#OpenApiXmlCommentSupport.generated.verified.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/XmlCommentDocumentationIdTests.CanMergeXmlCommentsWithDifferentDocumentationIdFormats#OpenApiXmlCommentSupport.generated.verified.cs index 2c8aa82f552b..a19d1f62eba1 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/XmlCommentDocumentationIdTests.CanMergeXmlCommentsWithDifferentDocumentationIdFormats#OpenApiXmlCommentSupport.generated.verified.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/XmlCommentDocumentationIdTests.CanMergeXmlCommentsWithDifferentDocumentationIdFormats#OpenApiXmlCommentSupport.generated.verified.cs @@ -1,4 +1,4 @@ -//HintName: OpenApiXmlCommentSupport.generated.cs +//HintName: OpenApiXmlCommentSupport.generated.cs //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -515,9 +515,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(context.JsonTypeInfo.Type.CreateDocumentationId()), out var typeComment)) { schema.Description = typeComment.Summary; - if (typeComment.Examples?.FirstOrDefault() is { } jsonString) + if (typeComment.Examples is { Count: > 0 } typeExamples) { - schema.Examples = [jsonString.Parse()]; + schema.Examples = typeExamples.ConvertAll(example => example.Parse()!); } } @@ -541,9 +541,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext { // Inlined schema schema.Description = description; - if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) + if (propertyComment.Examples is { Count: > 0 } propertyExamples) { - schema.Examples = [jsonString.Parse()]; + schema.Examples = propertyExamples.ConvertAll(example => example.Parse()!); } } else diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/XmlCommentDocumentationIdTests.ShouldNotDuplicateDocumentationIds#OpenApiXmlCommentSupport.generated.verified.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/XmlCommentDocumentationIdTests.ShouldNotDuplicateDocumentationIds#OpenApiXmlCommentSupport.generated.verified.cs index af3a74d1bf9f..5385e2abf38f 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/XmlCommentDocumentationIdTests.ShouldNotDuplicateDocumentationIds#OpenApiXmlCommentSupport.generated.verified.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/XmlCommentDocumentationIdTests.ShouldNotDuplicateDocumentationIds#OpenApiXmlCommentSupport.generated.verified.cs @@ -1,4 +1,4 @@ -//HintName: OpenApiXmlCommentSupport.generated.cs +//HintName: OpenApiXmlCommentSupport.generated.cs //------------------------------------------------------------------------------ // // This code was generated by a tool. @@ -518,9 +518,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(context.JsonTypeInfo.Type.CreateDocumentationId()), out var typeComment)) { schema.Description = typeComment.Summary; - if (typeComment.Examples?.FirstOrDefault() is { } jsonString) + if (typeComment.Examples is { Count: > 0 } typeExamples) { - schema.Examples = [jsonString.Parse()]; + schema.Examples = typeExamples.ConvertAll(example => example.Parse()!); } } @@ -544,9 +544,9 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext { // Inlined schema schema.Description = description; - if (propertyComment.Examples?.FirstOrDefault() is { } jsonString) + if (propertyComment.Examples is { Count: > 0 } propertyExamples) { - schema.Examples = [jsonString.Parse()]; + schema.Examples = propertyExamples.ConvertAll(example => example.Parse()!); } } else From eb83e15da3468baadee0c5da0c4214c089ddc83a Mon Sep 17 00:00:00 2001 From: Pradeep Ramola Date: Mon, 30 Nov 2026 01:38:23 -0500 Subject: [PATCH 3/3] Cover multiple schema examples from external XML docs --- .../AdditionalTextsTests.Schemas.cs | 10 ++++++++++ ...exts#OpenApiXmlCommentSupport.generated.verified.cs | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/AdditionalTextsTests.Schemas.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/AdditionalTextsTests.Schemas.cs index d38522051907..31b9873f209a 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/AdditionalTextsTests.Schemas.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/AdditionalTextsTests.Schemas.cs @@ -121,6 +121,8 @@ public class TodoWithDescription public string Description { get; set; } } +/// { "stringType": "First example" } +/// { "stringType": "Second example" } public class TypeWithExamples { /// true @@ -138,6 +140,7 @@ public class TypeWithExamples /// 2022-01-01 public DateOnly DateOnlyType { get; set; } /// Hello, World! + /// Goodbye, World! public string StringType { get; set; } /// 2d8f1eac-b5c6-4e29-8c62-4d9d75ef3d3d public Guid GuidType { get; set; } @@ -220,6 +223,10 @@ await SnapshotTestHelper.VerifyOpenApi(compilation, additionalAssemblies, docume path = document.Paths["/type-with-examples"].Operations[HttpMethod.Post]; var typeWithExamples = path.RequestBody.Content["application/json"].Schema; + Assert.Equal(2, typeWithExamples.Examples!.Count); + Assert.True(JsonNode.DeepEquals(JsonNode.Parse("""{ "stringType": "First example" }"""), typeWithExamples.Examples![0])); + Assert.True(JsonNode.DeepEquals(JsonNode.Parse("""{ "stringType": "Second example" }"""), typeWithExamples.Examples![1])); + var booleanTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["booleanType"].Examples![0]); Assert.True(booleanTypeExample.GetValue()); @@ -243,6 +250,9 @@ await SnapshotTestHelper.VerifyOpenApi(compilation, additionalAssemblies, docume var stringTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["stringType"].Examples![0]); Assert.Equal("Hello, World!", stringTypeExample.GetValue()); + Assert.Equal(2, typeWithExamples.Properties["stringType"].Examples!.Count); + var secondStringTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["stringType"].Examples![1]); + Assert.Equal("Goodbye, World!", secondStringTypeExample.GetValue()); var guidTypeExample = Assert.IsAssignableFrom(typeWithExamples.Properties["guidType"].Examples![0]); Assert.Equal("2d8f1eac-b5c6-4e29-8c62-4d9d75ef3d3d", guidTypeExample.GetValue()); diff --git a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AdditionalTextsTests.CanHandleXmlForSchemasInAdditionalTexts#OpenApiXmlCommentSupport.generated.verified.cs b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AdditionalTextsTests.CanHandleXmlForSchemasInAdditionalTexts#OpenApiXmlCommentSupport.generated.verified.cs index 8f2f7bf169d2..9af30f3980b6 100644 --- a/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AdditionalTextsTests.CanHandleXmlForSchemasInAdditionalTexts#OpenApiXmlCommentSupport.generated.verified.cs +++ b/src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AdditionalTextsTests.CanHandleXmlForSchemasInAdditionalTexts#OpenApiXmlCommentSupport.generated.verified.cs @@ -65,6 +65,7 @@ file static class XmlCommentCache cache.Add(@"P:ClassLibrary.TodoWithDescription.Id", new XmlComment(@"The identifier of the todo.", null, null, null, null, false, null, null, null)); cache.Add(@"P:ClassLibrary.TodoWithDescription.Name", new XmlComment(null, null, null, null, @"The name of the todo.", false, null, null, null)); cache.Add(@"P:ClassLibrary.TodoWithDescription.Description", new XmlComment(@"A description of the todo.", null, null, null, @"Another description of the todo.", false, null, null, null)); + cache.Add(@"T:ClassLibrary.TypeWithExamples", new XmlComment(null, null, null, null, null, false, [@"{ ""stringType"": ""First example"" }", @"{ ""stringType"": ""Second example"" }"], null, null)); cache.Add(@"P:ClassLibrary.TypeWithExamples.BooleanType", new XmlComment(null, null, null, null, null, false, [@"true"], null, null)); cache.Add(@"P:ClassLibrary.TypeWithExamples.IntegerType", new XmlComment(null, null, null, null, null, false, [@"42"], null, null)); cache.Add(@"P:ClassLibrary.TypeWithExamples.LongType", new XmlComment(null, null, null, null, null, false, [@"1234567890123456789"], null, null)); @@ -72,7 +73,7 @@ file static class XmlCommentCache cache.Add(@"P:ClassLibrary.TypeWithExamples.FloatType", new XmlComment(null, null, null, null, null, false, [@"3.14"], null, null)); cache.Add(@"P:ClassLibrary.TypeWithExamples.DateTimeType", new XmlComment(null, null, null, null, null, false, [@"2022-01-01T00:00:00Z"], null, null)); cache.Add(@"P:ClassLibrary.TypeWithExamples.DateOnlyType", new XmlComment(null, null, null, null, null, false, [@"2022-01-01"], null, null)); - cache.Add(@"P:ClassLibrary.TypeWithExamples.StringType", new XmlComment(null, null, null, null, null, false, [@"Hello, World!"], null, null)); + cache.Add(@"P:ClassLibrary.TypeWithExamples.StringType", new XmlComment(null, null, null, null, null, false, [@"Hello, World!", @"Goodbye, World!"], null, null)); cache.Add(@"P:ClassLibrary.TypeWithExamples.GuidType", new XmlComment(null, null, null, null, null, false, [@"2d8f1eac-b5c6-4e29-8c62-4d9d75ef3d3d"], null, null)); cache.Add(@"P:ClassLibrary.TypeWithExamples.TimeOnlyType", new XmlComment(null, null, null, null, null, false, [@"12:30:45"], null, null)); cache.Add(@"P:ClassLibrary.TypeWithExamples.TimeSpanType", new XmlComment(null, null, null, null, null, false, [@"P3DT4H5M"], null, null));