Skip to content

Commit 4df3d53

Browse files
Annotate TryLookupByType for nullability (#3719)
* Annotate TryLookupByType for nullability * Address review comments - Apply review comments from #3662. - Tweak implementation. * Fix formatting Add missing space. --------- Co-authored-by: Wajahat Ahmad <[email protected]>
1 parent ff2ceaa commit 4df3d53

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SchemaRepository.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ public class SchemaRepository(string documentName = null)
88

99
public string DocumentName { get; } = documentName;
1010

11-
public Dictionary<string, IOpenApiSchema> Schemas { get; private set; } = [];
11+
public Dictionary<string, IOpenApiSchema> Schemas { get; } = [];
1212

1313
public void RegisterType(Type type, string schemaId)
1414
{
@@ -24,16 +24,17 @@ public void RegisterType(Type type, string schemaId)
2424
_reservedIds.Add(type, schemaId);
2525
}
2626

27-
public bool TryLookupByType(Type type, out OpenApiSchemaReference referenceSchema)
27+
public bool TryLookupByType(Type type, [System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out OpenApiSchemaReference referenceSchema)
2828
{
29-
if (_reservedIds.TryGetValue(type, out string schemaId))
29+
referenceSchema = null;
30+
bool result = _reservedIds.TryGetValue(type, out string schemaId);
31+
32+
if (result)
3033
{
3134
referenceSchema = new OpenApiSchemaReference(schemaId);
32-
return true;
3335
}
3436

35-
referenceSchema = null;
36-
return false;
37+
return result;
3738
}
3839

3940
public OpenApiSchemaReference AddDefinition(string schemaId, OpenApiSchema schema)

0 commit comments

Comments
 (0)