domaindrivendev/Swashbuckle.AspNetCore

Please annotate SchemaRepository.TryLookupByType

Aberta

#3.659 aberto em 15 de nov. de 2025

 (3 comentários) (2 reações) (0 responsável)C# (1.342 forks)batch import
good first issuehelp-wanted

Métricas do repositório

Stars
 (5.495 estrelas)
Métricas de merge de PR
 (Métricas PR pendentes)

Description

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:

Guia do colaborador