blob: 4967cc6ae1a5d9d75cb433e38179de3d470d1341 (
plain)
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
|
using NSwag.Generation.Processors;
using NSwag.Generation.Processors.Contexts;
using System.Collections.Generic;
namespace Timeline.Swagger
{
/// <summary>
/// Swagger operation processor that adds default description to response.
/// </summary>
public class DefaultDescriptionOperationProcessor : IOperationProcessor
{
private readonly Dictionary<string, string> defaultDescriptionMap = new Dictionary<string, string>
{
["200"] = "Succeeded to perform the operation.",
["304"] = "Item does not change.",
["400"] = "See code and message for error info.",
["401"] = "You need to log in to perform this operation.",
["403"] = "You have no permission to perform the operation.",
["404"] = "Item does not exist. See code and message for error info."
};
/// <inheritdoc/>
public bool Process(OperationProcessorContext context)
{
var responses = context.OperationDescription.Operation.Responses;
foreach (var (httpStatusCode, res) in responses)
{
if (!string.IsNullOrEmpty(res.Description)) continue;
if (defaultDescriptionMap.ContainsKey(httpStatusCode))
{
res.Description = defaultDescriptionMap[httpStatusCode];
}
}
return true;
}
}
}
|