You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Only set a schema property description when it's not a schema reference
Update XmlCommentGenerator.Emitter.cs to skip applying property descriptions when it's a schema reference.
Schema transformers get the full schema and not the schema reference. So when the description is updated it would update it for all locations.
public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext context, CancellationToken cancellationToken)
451
451
{
452
-
if (context.JsonPropertyInfo is { AttributeProvider: PropertyInfo propertyInfo })
452
+
// Apply comments from the type
453
+
if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(context.JsonTypeInfo.Type.CreateDocumentationId()), out var typeComment))
454
+
{
455
+
schema.Description = typeComment.Summary;
456
+
if (typeComment.Examples?.FirstOrDefault() is { } jsonString)
457
+
{
458
+
schema.Example = jsonString.Parse();
459
+
}
460
+
}
461
+
462
+
var isPropertyInlinedSchema = schema.Metadata is null
463
+
|| !schema.Metadata.TryGetValue("x-schema-id", out var schemaId)
464
+
|| string.IsNullOrEmpty(schemaId as string);
465
+
if (isPropertyInlinedSchema && context.JsonPropertyInfo is { AttributeProvider: PropertyInfo propertyInfo })
453
466
{
467
+
// Apply comments from the property
454
468
if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(propertyInfo.CreateDocumentationId()), out var propertyComment))
@@ -460,14 +474,6 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
460
474
}
461
475
}
462
476
}
463
-
if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(context.JsonTypeInfo.Type.CreateDocumentationId()), out var typeComment))
464
-
{
465
-
schema.Description = typeComment.Summary;
466
-
if (typeComment.Examples?.FirstOrDefault() is { } jsonString)
467
-
{
468
-
schema.Example = jsonString.Parse();
469
-
}
470
-
}
471
477
return Task.CompletedTask;
472
478
}
473
479
}
@@ -507,6 +513,7 @@ file static class GeneratedServiceCollectionExtensions
Assert.Equal("This class validates the behavior for mapping\ngeneric types to open generics for use in\ntypeof expressions.",genericParent.Description,ignoreLineEndingDifferences:true);
517
517
Assert.Equal("This property is a nullable value type.",genericParent.Properties["id"].Description);
518
518
Assert.Equal("This property is a nullable reference type.",genericParent.Properties["name"].Description);
519
-
Assert.Equal("This property is a generic type containing a tuple.",genericParent.Properties["taskOfTupleProp"].Description);
520
-
Assert.Equal("This property is a tuple with a generic type inside.",genericParent.Properties["tupleWithGenericProp"].Description);
521
-
Assert.Equal("This property is a tuple with a nested generic type inside.",genericParent.Properties["tupleWithNestedGenericProp"].Description);
519
+
//Assert.Equal("This property is a generic type containing a tuple.", genericParent.Properties["taskOfTupleProp"].Description);
520
+
//Assert.Equal("This property is a tuple with a generic type inside.", genericParent.Properties["tupleWithGenericProp"].Description);
521
+
//Assert.Equal("This property is a tuple with a nested generic type inside.", genericParent.Properties["tupleWithNestedGenericProp"].Description);
Copy file name to clipboardExpand all lines: src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AddOpenApiTests.CanInterceptAddOpenApi#OpenApiXmlCommentSupport.generated.verified.cs
Copy file name to clipboardExpand all lines: src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AdditionalTextsTests.CanHandleXmlForSchemasInAdditionalTexts#OpenApiXmlCommentSupport.generated.verified.cs
Copy file name to clipboardExpand all lines: src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/CompletenessTests.SupportsAllXmlTagsOnSchemas#OpenApiXmlCommentSupport.generated.verified.cs
Copy file name to clipboardExpand all lines: src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsXmlCommentsOnOperationsFromControllers#OpenApiXmlCommentSupport.generated.verified.cs
Copy file name to clipboardExpand all lines: src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsXmlCommentsOnOperationsFromMinimalApis#OpenApiXmlCommentSupport.generated.verified.cs
0 commit comments