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
{
///
/// 将数据遍历静态页面中
///
/// 静态页面地址
/// 获取到的文件数据
///
public static string GeneritorSwaggerHtml(string templatePath, OpenApiDocument model)
{
var template = System.IO.File.ReadAllText(templatePath);
return string.Empty;
}
public static Dictionary GetBodyParam(IDictionary schemas, string schemaName)
{
if (schemas.ContainsKey(schemaName))
{
OpenApiSchema schema = schemas[schemaName];
Dictionary pairs = new Dictionary();
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 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;
}
}
}