tangxu
2024-03-26 edd23f115dba31d764fdaf75a6207d888d0419d3
WebApi/App_Start/SwaggerConfig.cs
@@ -1,27 +1,16 @@
using System.Web.Http;
using WebActivatorEx;
using IStation.WebApi;
using Swashbuckle.Application;
using System;
using System.Web;
[assembly: PreApplicationStartMethod(typeof(SPump.TransferApi.SwaggerConfig), "Register")]
[assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")]
namespace SPump.TransferApi
namespace IStation.WebApi
{
    /// <summary>
    /// SwaggerConfig
    /// </summary>
    public class SwaggerConfig
    {
        /// <summary>
        /// 注册
        /// </summary>
        public static void Register()
        {
            var isUseSwagger = System.Configuration.ConfigurationManager.AppSettings["IsUseSwagger"];
            if(!string.IsNullOrEmpty(isUseSwagger) && !Convert.ToBoolean(isUseSwagger))
            {
                return;
            }
            var thisAssembly = typeof(SwaggerConfig).Assembly;
            GlobalConfiguration.Configuration
@@ -43,7 +32,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", "义维SPump api接口平台");
                        c.SingleApiVersion("v1", "IStation.WebApi");
                        // If you want the output Swagger docs to be indented properly, enable the "PrettyPrint" option.
                        //
@@ -112,7 +101,7 @@
                        // those comments into the generated docs and UI. You can enable this by providing the path to one or
                        // more Xml comment files.
                        //
                        c.IncludeXmlComments(GetXmlCommentsPath());
                        //c.IncludeXmlComments(GetXmlCommentsPath());
                        // 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.
@@ -193,7 +182,7 @@
                        // Use the "DocumentTitle" option to change the Document title.
                        // Very helpful when you have multiple Swagger pages open, to tell them apart.
                        //
                        c.DocumentTitle("Spump api ƽ̨");
                        //c.DocumentTitle("My Swagger UI");
                        // Use the "InjectStylesheet" option to enrich the UI with one or more additional CSS stylesheets.
                        // The file must be included in your project as an "Embedded Resource", and then the resource's
@@ -261,11 +250,6 @@
                        //
                        //c.EnableApiKeySupport("apiKey", "header");
                    });
        }
        private static string GetXmlCommentsPath()
        {
            return String.Format(@"{0}bin\SPump.TransferApi.xml", System.AppDomain.CurrentDomain.BaseDirectory);
        }
    }
}