-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathSwaggerGenOptionsExt.cs
More file actions
53 lines (48 loc) · 1.88 KB
/
SwaggerGenOptionsExt.cs
File metadata and controls
53 lines (48 loc) · 1.88 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections.Frozen;
using System.Reflection;
using System.Runtime.CompilerServices;
using AltaSoft.DomainPrimitives.OpenApiExtensions;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi;
using Swashbuckle.AspNetCore.SwaggerGen;
// ReSharper disable UnusedMember.Global
namespace AltaSoft.DomainPrimitives.SwaggerExtensions;
/// <summary>
/// A static class providing methods to configure Swagger mappings for DomainPrimitive types.
/// </summary>
public static class SwaggerGenOptionsExt
{
/// <param name="options">The SwaggerGenOptions to which the mappings will be added.</param>
extension(SwaggerGenOptions options)
{
/// <summary>
/// Adds Swagger mappings for all DomainPrimitive types to the specified SwaggerGenOptions.
/// </summary>
/// <param name="assemblies">The assemblies containing the DomainPrimitive types.</param>
public void AddDomainPrimitivesSwaggerMappings(params Assembly[] assemblies)
{
foreach (var assembly in assemblies)
{
OpenApiHelperProcessor.ProcessAssembly(assembly, options.ProcessSwaggerOptions);
}
}
/// <summary>
/// Adds Swagger mappings for all DomainPrimitive types to the specified SwaggerGenOptions.
/// </summary>
public void AddAllDomainPrimitivesSwaggerMappings()
{
OpenApiHelperProcessor.ProcessOpenApiHelpers(options.ProcessSwaggerOptions);
}
/// <summary>
/// Processes swagger options
/// </summary>
/// <returns></returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private void ProcessSwaggerOptions(FrozenDictionary<Type, OpenApiSchema> values)
{
foreach (var (type, schema) in values)
options.MapType(type, () => schema);
}
}
}