From ac769e656b122ff569c3f1534701b71e00fed586 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 27 Oct 2020 19:21:35 +0800 Subject: Split front and back end. --- .../Swagger/ByteDataRequestOperationProcessor.cs | 27 ++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 BackEnd/Timeline/Swagger/ByteDataRequestOperationProcessor.cs (limited to 'BackEnd/Timeline/Swagger/ByteDataRequestOperationProcessor.cs') diff --git a/BackEnd/Timeline/Swagger/ByteDataRequestOperationProcessor.cs b/BackEnd/Timeline/Swagger/ByteDataRequestOperationProcessor.cs new file mode 100644 index 00000000..887831ac --- /dev/null +++ b/BackEnd/Timeline/Swagger/ByteDataRequestOperationProcessor.cs @@ -0,0 +1,27 @@ +using NJsonSchema; +using NSwag; +using NSwag.Generation.Processors; +using NSwag.Generation.Processors.Contexts; +using System.Linq; +using Timeline.Models; + +namespace Timeline.Swagger +{ + /// + /// Coerce ByteData body type into the right one. + /// + public class ByteDataRequestOperationProcessor : IOperationProcessor + { + /// + 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(); + } + return true; + } + } +} -- cgit v1.2.3