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;
|
}
|
}
|
}
|