Skip to content

Commit c6f4f23

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

10 files changed

+29
-28
lines changed

src/OpenApi/gen/XmlCommentGenerator.Emitter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
469469
|| string.IsNullOrEmpty(schemaId as string))
470470
{
471471
// Inlined schema
472-
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
472+
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
473473
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
474474
{
475475
schema.Example = jsonString.Parse();
@@ -478,10 +478,10 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
478478
else
479479
{
480480
// Schema Reference
481-
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
481+
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
482482
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
483483
{
484-
schema.Metadata["x-ref-example"] = jsonString.Parse();
484+
schema.Metadata["x-ref-example"] = jsonString.Parse()!;
485485
}
486486
}
487487
}

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: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
451451
|| string.IsNullOrEmpty(schemaId as string))
452452
{
453453
// Inlined schema
454-
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
454+
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
455455
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
456456
{
457457
schema.Example = jsonString.Parse();
@@ -460,10 +460,10 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
460460
else
461461
{
462462
// Schema Reference
463-
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
463+
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
464464
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
465465
{
466-
schema.Metadata["x-ref-example"] = jsonString.Parse();
466+
schema.Metadata["x-ref-example"] = jsonString.Parse()!;
467467
}
468468
}
469469
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
480480
|| string.IsNullOrEmpty(schemaId as string))
481481
{
482482
// Inlined schema
483-
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
483+
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
484484
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
485485
{
486486
schema.Example = jsonString.Parse();
@@ -489,10 +489,10 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
489489
else
490490
{
491491
// Schema Reference
492-
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
492+
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
493493
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
494494
{
495-
schema.Metadata["x-ref-example"] = jsonString.Parse();
495+
schema.Metadata["x-ref-example"] = jsonString.Parse()!;
496496
}
497497
}
498498
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
572572
|| string.IsNullOrEmpty(schemaId as string))
573573
{
574574
// Inlined schema
575-
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
575+
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
576576
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
577577
{
578578
schema.Example = jsonString.Parse();
@@ -581,10 +581,10 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
581581
else
582582
{
583583
// Schema Reference
584-
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
584+
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
585585
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
586586
{
587-
schema.Metadata["x-ref-example"] = jsonString.Parse();
587+
schema.Metadata["x-ref-example"] = jsonString.Parse()!;
588588
}
589589
}
590590
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
455455
|| string.IsNullOrEmpty(schemaId as string))
456456
{
457457
// Inlined schema
458-
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
458+
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
459459
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
460460
{
461461
schema.Example = jsonString.Parse();
@@ -464,10 +464,10 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
464464
else
465465
{
466466
// Schema Reference
467-
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
467+
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
468468
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
469469
{
470-
schema.Metadata["x-ref-example"] = jsonString.Parse();
470+
schema.Metadata["x-ref-example"] = jsonString.Parse()!;
471471
}
472472
}
473473
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
473473
|| string.IsNullOrEmpty(schemaId as string))
474474
{
475475
// Inlined schema
476-
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
476+
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
477477
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
478478
{
479479
schema.Example = jsonString.Parse();
@@ -482,10 +482,10 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
482482
else
483483
{
484484
// Schema Reference
485-
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
485+
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
486486
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
487487
{
488-
schema.Metadata["x-ref-example"] = jsonString.Parse();
488+
schema.Metadata["x-ref-example"] = jsonString.Parse()!;
489489
}
490490
}
491491
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
481481
|| string.IsNullOrEmpty(schemaId as string))
482482
{
483483
// Inlined schema
484-
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
484+
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
485485
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
486486
{
487487
schema.Example = jsonString.Parse();
@@ -490,10 +490,10 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
490490
else
491491
{
492492
// Schema Reference
493-
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
493+
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
494494
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
495495
{
496-
schema.Metadata["x-ref-example"] = jsonString.Parse();
496+
schema.Metadata["x-ref-example"] = jsonString.Parse()!;
497497
}
498498
}
499499
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
460460
|| string.IsNullOrEmpty(schemaId as string))
461461
{
462462
// Inlined schema
463-
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
463+
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
464464
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
465465
{
466466
schema.Example = jsonString.Parse();
@@ -469,10 +469,10 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
469469
else
470470
{
471471
// Schema Reference
472-
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
472+
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
473473
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
474474
{
475-
schema.Metadata["x-ref-example"] = jsonString.Parse();
475+
schema.Metadata["x-ref-example"] = jsonString.Parse()!;
476476
}
477477
}
478478
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
452452
|| string.IsNullOrEmpty(schemaId as string))
453453
{
454454
// Inlined schema
455-
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
455+
schema.Description = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
456456
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
457457
{
458458
schema.Example = jsonString.Parse();
@@ -461,10 +461,10 @@ public Task TransformAsync(OpenApiSchema schema, OpenApiSchemaTransformerContext
461461
else
462462
{
463463
// Schema Reference
464-
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary;
464+
schema.Metadata["x-ref-description"] = propertyComment.Value ?? propertyComment.Returns ?? propertyComment.Summary!;
465465
if (propertyComment.Examples?.FirstOrDefault() is { } jsonString)
466466
{
467-
schema.Metadata["x-ref-example"] = jsonString.Parse();
467+
schema.Metadata["x-ref-example"] = jsonString.Parse()!;
468468
}
469469
}
470470
}

0 commit comments

Comments
 (0)