domaindrivendev/Swashbuckle.AspNetCore

Please annotate SchemaRepository.TryLookupByType

Offen

#3.659 geöffnet am 15.11.2025

 (3 Kommentare) (2 Reaktionen) (0 zugewiesene Personen)C# (1.341 Forks)batch import
good first issuehelp-wanted

Repository-Metriken

Stars
 (5.497 Sterne)
PR-Merge-Metriken
 (Durchschn. Merge 3T 14h) (45 gemergte PRs in 30 T)

Beschreibung

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:

Contributor Guide