Skip to content

Commit d781b57

Browse files
committed
Fix null assignment warning
1 parent 86b5753 commit d781b57

10 files changed

+47
-37
lines changed

src/OpenApi/gen/XmlCommentGenerator.Emitter.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -464,12 +464,13 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
464464
// Apply comments from the property
465465
if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(propertyInfo.CreateDocumentationId()), out var propertyComment))
466466
{
467-
if(schema.Metadata is null
467+
var isInlinedSchema = schema.Metadata is null
468468
|| !schema.Metadata.TryGetValue("x-schema-id", out var schemaId)
469-
|| string.IsNullOrEmpty(schemaId as string))
469+
|| string.IsNullOrEmpty(schemaId as string);
470+
if(isInlinedSchema)
470471
{
471472
// Inlined schema
472-
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
473+
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
473474
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
474475
{
475476
schema.Example = jsonString.Parse();
@@ -478,7 +479,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
478479
else
479480
{
480481
// Schema Reference
481-
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
482+
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
482483
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
483484
{
484485
schema.Metadata["x-ref-example"] = jsonString.Parse();

src/OpenApi/src/Services/Schemas/OpenApiSchemaService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ internal sealed class OpenApiSchemaService(
101101
{
102102
schema.ApplyNullabilityContextInfo(jsonPropertyInfo);
103103
}
104-
if (context.PropertyInfo is { AttributeProvider: { } attributeProvider })
104+
var isInlinedSchema = schema["x-schema-id"] is null;
105+
if (isInlinedSchema && context.PropertyInfo is { AttributeProvider: { } attributeProvider })
105106
{
106107
if (attributeProvider.GetCustomAttributes(inherit: false).OfType<ValidationAttribute>() is { } validationAttributes)
107108
{

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AddOpenApiTests.CanInterceptAddOpenApi#OpenApiXmlCommentSupport.generated.verified.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -446,12 +446,13 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
446446
// Apply comments from the property
447447
if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(propertyInfo.CreateDocumentationId()), out var propertyComment))
448448
{
449-
if(schema.Metadata is null
449+
var isInlinedSchema = schema.Metadata is null
450450
|| !schema.Metadata.TryGetValue("x-schema-id", out var schemaId)
451-
|| string.IsNullOrEmpty(schemaId as string))
451+
|| string.IsNullOrEmpty(schemaId as string);
452+
if(isInlinedSchema)
452453
{
453454
// Inlined schema
454-
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
455+
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
455456
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
456457
{
457458
schema.Example = jsonString.Parse();
@@ -460,7 +461,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
460461
else
461462
{
462463
// Schema Reference
463-
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
464+
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
464465
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
465466
{
466467
schema.Metadata["x-ref-example"] = jsonString.Parse();

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/AdditionalTextsTests.CanHandleXmlForSchemasInAdditionalTexts#OpenApiXmlCommentSupport.generated.verified.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,12 +475,13 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
475475
// Apply comments from the property
476476
if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(propertyInfo.CreateDocumentationId()), out var propertyComment))
477477
{
478-
if(schema.Metadata is null
478+
var isInlinedSchema = schema.Metadata is null
479479
|| !schema.Metadata.TryGetValue("x-schema-id", out var schemaId)
480-
|| string.IsNullOrEmpty(schemaId as string))
480+
|| string.IsNullOrEmpty(schemaId as string);
481+
if(isInlinedSchema)
481482
{
482483
// Inlined schema
483-
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
484+
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
484485
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
485486
{
486487
schema.Example = jsonString.Parse();
@@ -489,7 +490,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
489490
else
490491
{
491492
// Schema Reference
492-
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
493+
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
493494
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
494495
{
495496
schema.Metadata["x-ref-example"] = jsonString.Parse();

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/CompletenessTests.SupportsAllXmlTagsOnSchemas#OpenApiXmlCommentSupport.generated.verified.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -567,12 +567,13 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
567567
// Apply comments from the property
568568
if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(propertyInfo.CreateDocumentationId()), out var propertyComment))
569569
{
570-
if(schema.Metadata is null
570+
var isInlinedSchema = schema.Metadata is null
571571
|| !schema.Metadata.TryGetValue("x-schema-id", out var schemaId)
572-
|| string.IsNullOrEmpty(schemaId as string))
572+
|| string.IsNullOrEmpty(schemaId as string);
573+
if(isInlinedSchema)
573574
{
574575
// Inlined schema
575-
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
576+
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
576577
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
577578
{
578579
schema.Example = jsonString.Parse();
@@ -581,7 +582,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
581582
else
582583
{
583584
// Schema Reference
584-
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
585+
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
585586
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
586587
{
587588
schema.Metadata["x-ref-example"] = jsonString.Parse();

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsXmlCommentsOnOperationsFromControllers#OpenApiXmlCommentSupport.generated.verified.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -450,12 +450,13 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
450450
// Apply comments from the property
451451
if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(propertyInfo.CreateDocumentationId()), out var propertyComment))
452452
{
453-
if(schema.Metadata is null
453+
var isInlinedSchema = schema.Metadata is null
454454
|| !schema.Metadata.TryGetValue("x-schema-id", out var schemaId)
455-
|| string.IsNullOrEmpty(schemaId as string))
455+
|| string.IsNullOrEmpty(schemaId as string);
456+
if(isInlinedSchema)
456457
{
457458
// Inlined schema
458-
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
459+
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
459460
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
460461
{
461462
schema.Example = jsonString.Parse();
@@ -464,7 +465,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
464465
else
465466
{
466467
// Schema Reference
467-
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
468+
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
468469
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
469470
{
470471
schema.Metadata["x-ref-example"] = jsonString.Parse();

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/OperationTests.SupportsXmlCommentsOnOperationsFromMinimalApis#OpenApiXmlCommentSupport.generated.verified.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -468,12 +468,13 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
468468
// Apply comments from the property
469469
if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(propertyInfo.CreateDocumentationId()), out var propertyComment))
470470
{
471-
if(schema.Metadata is null
471+
var isInlinedSchema = schema.Metadata is null
472472
|| !schema.Metadata.TryGetValue("x-schema-id", out var schemaId)
473-
|| string.IsNullOrEmpty(schemaId as string))
473+
|| string.IsNullOrEmpty(schemaId as string);
474+
if(isInlinedSchema)
474475
{
475476
// Inlined schema
476-
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
477+
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
477478
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
478479
{
479480
schema.Example = jsonString.Parse();
@@ -482,7 +483,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
482483
else
483484
{
484485
// Schema Reference
485-
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
486+
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
486487
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
487488
{
488489
schema.Metadata["x-ref-example"] = jsonString.Parse();

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/SchemaTests.SupportsXmlCommentsOnSchemas#OpenApiXmlCommentSupport.generated.verified.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -476,12 +476,13 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
476476
// Apply comments from the property
477477
if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(propertyInfo.CreateDocumentationId()), out var propertyComment))
478478
{
479-
if(schema.Metadata is null
479+
var isInlinedSchema = schema.Metadata is null
480480
|| !schema.Metadata.TryGetValue("x-schema-id", out var schemaId)
481-
|| string.IsNullOrEmpty(schemaId as string))
481+
|| string.IsNullOrEmpty(schemaId as string);
482+
if(isInlinedSchema)
482483
{
483484
// Inlined schema
484-
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
485+
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
485486
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
486487
{
487488
schema.Example = jsonString.Parse();
@@ -490,7 +491,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
490491
else
491492
{
492493
// Schema Reference
493-
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
494+
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
494495
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
495496
{
496497
schema.Metadata["x-ref-example"] = jsonString.Parse();

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/SchemaTests.XmlCommentsOnPropertiesShouldApplyToSchemaReferences#OpenApiXmlCommentSupport.generated.verified.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -455,12 +455,13 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
455455
// Apply comments from the property
456456
if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(propertyInfo.CreateDocumentationId()), out var propertyComment))
457457
{
458-
if(schema.Metadata is null
458+
var isInlinedSchema = schema.Metadata is null
459459
|| !schema.Metadata.TryGetValue("x-schema-id", out var schemaId)
460-
|| string.IsNullOrEmpty(schemaId as string))
460+
|| string.IsNullOrEmpty(schemaId as string);
461+
if(isInlinedSchema)
461462
{
462463
// Inlined schema
463-
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
464+
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
464465
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
465466
{
466467
schema.Example = jsonString.Parse();
@@ -469,7 +470,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
469470
else
470471
{
471472
// Schema Reference
472-
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
473+
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
473474
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
474475
{
475476
schema.Metadata["x-ref-example"] = jsonString.Parse();

src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/XmlCommentDocumentationIdTests.CanMergeXmlCommentsWithDifferentDocumentationIdFormats#OpenApiXmlCommentSupport.generated.verified.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,12 +447,13 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
447447
// Apply comments from the property
448448
if (XmlCommentCache.Cache.TryGetValue(DocumentationCommentIdHelper.NormalizeDocId(propertyInfo.CreateDocumentationId()), out var propertyComment))
449449
{
450-
if(schema.Metadata is null
450+
var isInlinedSchema = schema.Metadata is null
451451
|| !schema.Metadata.TryGetValue("x-schema-id", out var schemaId)
452-
|| string.IsNullOrEmpty(schemaId as string))
452+
|| string.IsNullOrEmpty(schemaId as string);
453+
if(isInlinedSchema)
453454
{
454455
// Inlined schema
455-
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
456+
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
456457
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
457458
{
458459
schema.Example = jsonString.Parse();
@@ -461,7 +462,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
461462
else
462463
{
463464
// Schema Reference
464-
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
465+
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
465466
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
466467
{
467468
schema.Metadata["x-ref-example"] = jsonString.Parse();

0 commit comments

Comments
 (0)