aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-08-21 23:24:47 +0800
committercrupest <crupest@outlook.com>2020-08-21 23:24:47 +0800
commited324cdcec6d70cc9f93b57b2e3a5a35d3366048 (patch)
treed5690556040c53e5efd9a52c46f086b053829da4
parent96fe96b87abb9cdefd83cd26732bb251f90b4aa3 (diff)
downloadtimeline-ed324cdcec6d70cc9f93b57b2e3a5a35d3366048.tar.gz
timeline-ed324cdcec6d70cc9f93b57b2e3a5a35d3366048.tar.bz2
timeline-ed324cdcec6d70cc9f93b57b2e3a5a35d3366048.zip
...
-rw-r--r--Timeline/Startup.cs1
-rw-r--r--Timeline/Swagger/ByteDataRequestOperationProcessor.cs27
2 files changed, 28 insertions, 0 deletions
diff --git a/Timeline/Startup.cs b/Timeline/Startup.cs
index 408057e5..86bdaf54 100644
--- a/Timeline/Startup.cs
+++ b/Timeline/Startup.cs
@@ -115,6 +115,7 @@ namespace Timeline
}));
document.OperationProcessors.Add(new AspNetCoreOperationSecurityScopeProcessor("JWT"));
document.OperationProcessors.Add(new DefaultDescriptionOperationProcessor());
+ document.OperationProcessors.Add(new ByteDataRequestOperationProcessor());
});
if (!disableFrontEnd)
diff --git a/Timeline/Swagger/ByteDataRequestOperationProcessor.cs b/Timeline/Swagger/ByteDataRequestOperationProcessor.cs
new file mode 100644
index 00000000..887831ac
--- /dev/null
+++ b/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
+{
+ /// <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;
+ }
+ }
+}