-
-
Notifications
You must be signed in to change notification settings - Fork 162
Expand file tree
/
Copy pathSchemaRepositoryExtensions.cs
More file actions
28 lines (23 loc) · 1.07 KB
/
SchemaRepositoryExtensions.cs
File metadata and controls
28 lines (23 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using System.Diagnostics.CodeAnalysis;
using Microsoft.OpenApi;
using Swashbuckle.AspNetCore.SwaggerGen;
namespace JsonApiDotNetCore.OpenApi.Swashbuckle;
internal static class SchemaRepositoryExtensions
{
public static OpenApiSchemaReference LookupByType(this SchemaRepository schemaRepository, Type schemaType)
{
ArgumentNullException.ThrowIfNull(schemaRepository);
ArgumentNullException.ThrowIfNull(schemaType);
if (!schemaRepository.TryLookupByTypeSafe(schemaType, out OpenApiSchemaReference? referenceSchema))
{
throw new InvalidOperationException($"Reference schema for '{schemaType.Name}' does not exist.");
}
return referenceSchema;
}
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;
}
}