-
Notifications
You must be signed in to change notification settings - Fork 1
/
SortDataSchemasDocumentFilter.cs
30 lines (25 loc) · 1.11 KB
/
SortDataSchemasDocumentFilter.cs
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
namespace swashbuckle_stuff
{
using System;
using System.Reflection;
using Microsoft.OpenApi.Models;
using Newtonsoft.Json.Serialization;
using Swashbuckle.AspNetCore.SwaggerGen;
/// <summary>
/// Sort the data definitions that appear in the "Schemas" section of the Swagger page.
/// </summary>
public sealed class SortDataSchemasDocumentFilter : IDocumentFilter
{
/// <summary>
/// Sort the data definitions that appear in the "Schemas" section of the Swagger page.
/// </summary>
/// <param name="openApiDoc">The swagger document</param>
/// <param name="context">The filter context</param>
public void Apply(OpenApiDocument openApiDoc, DocumentFilterContext context)
{
if (openApiDoc == null) throw new ArgumentNullException(nameof(openApiDoc));
if (context == null) throw new ArgumentNullException(nameof(context));
openApiDoc.Components.Schemas = new System.Collections.Generic.SortedDictionary<string, OpenApiSchema>(openApiDoc.Components.Schemas);
}
}
}