diff options
author | crupest <crupest@outlook.com> | 2020-08-21 23:24:47 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2020-08-21 23:24:47 +0800 |
commit | ed324cdcec6d70cc9f93b57b2e3a5a35d3366048 (patch) | |
tree | d5690556040c53e5efd9a52c46f086b053829da4 | |
parent | 96fe96b87abb9cdefd83cd26732bb251f90b4aa3 (diff) | |
download | timeline-ed324cdcec6d70cc9f93b57b2e3a5a35d3366048.tar.gz timeline-ed324cdcec6d70cc9f93b57b2e3a5a35d3366048.tar.bz2 timeline-ed324cdcec6d70cc9f93b57b2e3a5a35d3366048.zip |
...
-rw-r--r-- | Timeline/Startup.cs | 1 | ||||
-rw-r--r-- | Timeline/Swagger/ByteDataRequestOperationProcessor.cs | 27 |
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;
+ }
+ }
+}
|