wankeda
9 小时以前 6cc35000a6e138cfad96e7b02f8aeddcdb4ba6bf
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace WIDESEAWCS_Core.ApiDoc
{
    public class HtmlHelper
    {
        /// <summary>
        /// 将数据遍历静态页面中
        /// </summary>
        /// <param name="templatePath">静态页面地址</param>
        /// <param name="model">获取到的文件数据</param>
        /// <returns></returns>
        public static string GeneritorSwaggerHtml(string templatePath, OpenApiDocument model)
        {
            var template = System.IO.File.ReadAllText(templatePath);
 
            return string.Empty;
        }
 
        
 
        public static Dictionary<string, object> GetBodyParam(IDictionary<string, OpenApiSchema> schemas, string schemaName)
        {
            if (schemas.ContainsKey(schemaName))
            {
                OpenApiSchema schema = schemas[schemaName];
                Dictionary<string, object> pairs = new Dictionary<string, object>();
                foreach (var pair in schema.Properties)
                {
                    if (pair.Value.Type == "object")
                    {
 
                    }
                    else if (pair.Value.Type == "array")
                    {
                        if (pair.Value.Items.Reference != null)
                        {
                            string childSchemaName = pair.Value.Items.Reference.Id;
                            Dictionary<string, object> keyValuePairs = GetBodyParam(schemas, childSchemaName);
                            if (keyValuePairs != null && keyValuePairs.Keys.Count > 0)
                            {
                                pairs.Add(pair.Key, keyValuePairs);
                            }
                        }
 
                    }
                    else
                    {
                        pairs.Add(pair.Key, new
                        {
                            ParamName = pair.Key,
                            Description = pair.Value.Description,
                            ParamType = pair.Value.Type,
                            Required = (schema.Required.FirstOrDefault(x => x == pair.Key) != null).ToString()
                        });
                    }
                }
                return pairs;
            }
            return null;
        }
    }
}