domaindrivendev/Swashbuckle.AspNetCore
Please annotate SchemaRepository.TryLookupByType
オープン
#3,659 opened on 2025/11/15
good first issuehelp-wanted
Repository metrics
- Stars
- (5,496 個のスター)
- PR merge metrics
- (平均マージ 3d 14h) (30d で 45 merged PRs)
説明
I was reviewing some code and noticed a hidden bug: null could be returned, but there was no compiler warning. This is because TryLookupByType lacks the [NotNullWhen(true)] annotation, which is used, for example, in IPAddress.TryParse.
It would be helpful if SchemaRepository.TryLookupByType were annotated for nullability, similar to my workaround below:
#nullable enable
public static bool TryLookupByTypeSafe(this SchemaRepository schemaRepository,
Type type, [NotNullWhen(true)] out OpenApiSchemaReference? referenceSchema)
{
bool result = schemaRepository.TryLookupByType(type,
out OpenApiSchemaReference? obliviousReferenceSchema);
referenceSchema = result ? obliviousReferenceSchema : null;
return result;
}
#nullable restore
And then the hidden bug becomes a compiler warning: