domaindrivendev/Swashbuckle.AspNetCore
Please annotate SchemaRepository.TryLookupByType
開放
#3,659 建立於 2025年11月15日
good first issuehelp-wanted
倉庫指標
- 星標
- (5,496 顆星)
- PR 合併指標
- (平均合併 3天 14小時) (30 天內合併 45 個 PR)
描述
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: