blob: 887831ac6a4948bff10cfd7883ce27d7110f986d (
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
|
using NJsonSchema;
using NSwag;
using NSwag.Generation.Processors;
using NSwag.Generation.Processors.Contexts;
using System.Linq;
using Timeline.Models;
namespace Timeline.Swagger
{
/// <summary>
/// Coerce ByteData body type into the right one.
/// </summary>
public class ByteDataRequestOperationProcessor : IOperationProcessor
{
/// <inheritdoc/>
public bool Process(OperationProcessorContext context)
{
var hasByteDataBody = context.MethodInfo.GetParameters().Where(p => p.ParameterType == typeof(ByteData)).Any();
if (hasByteDataBody)
{
var bodyParameter = context.OperationDescription.Operation.Parameters.Where(p => p.Kind == OpenApiParameterKind.Body).Single();
bodyParameter.Schema = JsonSchema.FromType<byte[]>();
}
return true;
}
}
}
|