kazelee
2025-05-15 1af49bdb3cdaa44a7e44ebdc843fb8180596365f
App_Start/SwaggerConfig.cs
File was renamed from AppStart/SwaggerConfig.cs
@@ -1,14 +1,49 @@
using System.Web.Http;
using WebActivatorEx;
using HH.WCS.Mobox3.Template;
using HH.WCS.Mobox3.DSZSH;
using Swashbuckle.Application;
using System.IO;
using System.Reflection;
using System;
using Swashbuckle.Examples;
[assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")]
namespace HH.WCS.Mobox3.Template
namespace HH.WCS.Mobox3.DSZSH
{
    public class SwaggerConfig
    {
        public static void Register(HttpConfiguration config) {
            var thisAssembly = typeof(SwaggerConfig).Assembly;
            config
                .EnableSwagger(c => {
                    c.SingleApiVersion("v1", "HH.WCS.Mobox3.DSZSH");
                    // 设置 XML 注释路径
                    var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
                    //var commentsFileName = Assembly.GetExecutingAssembly().GetName().Name + ".xml";
                    var commentsFileName = "bin\\Debug\\HH.WCS.Mobox3.DSZSH.xml";
                    var commentsFile = Path.Combine(baseDirectory, commentsFileName);
                    if (File.Exists(commentsFile)) {
                        c.IncludeXmlComments(commentsFile);
                    }
                    // 其他配置...
                    c.UseFullTypeNameInSchemaIds();
                    // 启用示例数据
                    //c.DescribeAllEnumsAsStrings();
                    //c.OperationFilter<ExamplesOperationFilter>();
                    //c.ModelFilter<ExamplesModelFilter>();
                })
                .EnableSwaggerUi(c => {
                    // UI 配置
                });
        }
        public static void Register()
        {
            var thisAssembly = typeof(SwaggerConfig).Assembly;
@@ -32,7 +67,7 @@
                        // hold additional metadata for an API. Version and title are required but you can also provide
                        // additional fields by chaining methods off SingleApiVersion.
                        //
                        c.SingleApiVersion("v1", "HH.WCS.Mobox3.Template");
                        c.SingleApiVersion("v1", "HH.WCS.Mobox3.DSZSH");
                        // If you want the output Swagger docs to be indented properly, enable the "PrettyPrint" option.
                        //
@@ -103,6 +138,10 @@
                        //
                        //c.IncludeXmlComments(GetXmlCommentsPath());
                        // 启用 XML 注释
                        var xmlFile = $"{System.AppDomain.CurrentDomain.BaseDirectory}\\HH.WCS.Mobox3.DSZSH.xml";
                        c.IncludeXmlComments(xmlFile);
                        // Swashbuckle makes a best attempt at generating Swagger compliant JSON schemas for the various types
                        // exposed in your API. However, there may be occasions when more control of the output is needed.
                        // This is supported through the "MapType" and "SchemaFilter" options: