aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Swagger/DocumentDescriptionDocumentProcessor.cs
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2020-10-31 00:42:06 +0800
committerGitHub <noreply@github.com>2020-10-31 00:42:06 +0800
commita3c97f6fb6313da2e8c0fac0b4c08f2ef4265d0f (patch)
treeee006874b0c93e9bfc76f141a092a8b9585a1f95 /Timeline/Swagger/DocumentDescriptionDocumentProcessor.cs
parent0c4caaebe2480e77918d5d7df234f0edaeab74ba (diff)
parent7ce0846d9ec968da3ea4f7ebcc6db26db8e49089 (diff)
downloadtimeline-a3c97f6fb6313da2e8c0fac0b4c08f2ef4265d0f.tar.gz
timeline-a3c97f6fb6313da2e8c0fac0b4c08f2ef4265d0f.tar.bz2
timeline-a3c97f6fb6313da2e8c0fac0b4c08f2ef4265d0f.zip
Merge pull request #161 from crupest/upgrade
Upgrade packages and split front end and back end.
Diffstat (limited to 'Timeline/Swagger/DocumentDescriptionDocumentProcessor.cs')
-rw-r--r--Timeline/Swagger/DocumentDescriptionDocumentProcessor.cs55
1 files changed, 0 insertions, 55 deletions
diff --git a/Timeline/Swagger/DocumentDescriptionDocumentProcessor.cs b/Timeline/Swagger/DocumentDescriptionDocumentProcessor.cs
deleted file mode 100644
index dc5ddd96..00000000
--- a/Timeline/Swagger/DocumentDescriptionDocumentProcessor.cs
+++ /dev/null
@@ -1,55 +0,0 @@
-using NSwag.Generation.Processors;
-using NSwag.Generation.Processors.Contexts;
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using System.Text;
-using System.Threading.Tasks;
-using Timeline.Models.Http;
-
-namespace Timeline.Swagger
-{
- public class DocumentDescriptionDocumentProcessor : IDocumentProcessor
- {
- private static Dictionary<string, int> GetAllErrorCodes()
- {
- var errorCodes = new Dictionary<string, int>();
-
- void RecursiveCheckErrorCode(Type type)
- {
- foreach (var field in type.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy)
- .Where(fi => fi.IsLiteral && !fi.IsInitOnly && fi.FieldType == typeof(int)))
- {
- var name = (type.FullName + "." + field.Name).Remove(0, typeof(ErrorCodes).FullName!.Length + 1).Replace("+", ".", StringComparison.OrdinalIgnoreCase);
- int value = (int)field.GetRawConstantValue()!;
- errorCodes.Add(name, value);
- }
-
- foreach (var nestedType in type.GetNestedTypes())
- {
- RecursiveCheckErrorCode(nestedType);
- }
- }
-
- RecursiveCheckErrorCode(typeof(ErrorCodes));
-
- return errorCodes;
- }
-
- public void Process(DocumentProcessorContext context)
- {
- StringBuilder description = new StringBuilder();
- description.AppendLine("# Error Codes");
- description.AppendLine("name | value");
- description.AppendLine("---- | -----");
- foreach (var (name, value) in GetAllErrorCodes())
- {
- description.AppendLine($"`{name}` | `{value}`");
- }
-
- context.Document.Info.Description = description.ToString();
- }
- }
-}