| | |
| | | using System.Web.Http; |
| | | using WebActivatorEx; |
| | | using HH.WCS.Mobox3.DSZSH; |
| | | using HH.WCS.Mobox3.Template; |
| | | using Swashbuckle.Application; |
| | | using System.IO; |
| | | using System.Reflection; |
| | | using System; |
| | | using Swashbuckle.Examples; |
| | | |
| | | [assembly: PreApplicationStartMethod(typeof(SwaggerConfig), "Register")] |
| | | |
| | | namespace HH.WCS.Mobox3.DSZSH |
| | | namespace HH.WCS.Mobox3.Template |
| | | { |
| | | 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; |
| | |
| | | // 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.DSZSH"); |
| | | c.SingleApiVersion("v1", "HH.WCS.Mobox3.Template"); |
| | | |
| | | // If you want the output Swagger docs to be indented properly, enable the "PrettyPrint" option. |
| | | // |
| | |
| | | //c.BasicAuth("basic") |
| | | // .Description("Basic HTTP Authentication"); |
| | | // |
| | | // NOTE: You must also configure 'EnableApiKeySupport' below in the SwaggerUI section |
| | | // NOTE: You must also configure 'EnableApiKeySupport' below in the SwaggerUI section |
| | | //c.ApiKey("apiKey") |
| | | // .Description("API Key Authentication") |
| | | // .Name("apiKey") |
| | |
| | | // more Xml comment files. |
| | | // |
| | | //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. |