From 0fb0f17319ecf71d66b96a6acfd07f754be9443e Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期四, 24 十月 2024 13:44:38 +0800
Subject: [PATCH] WCS添加穿梭车信息表,修改任务信息表
---
项目代码/WMS/WIDESEA_WMSServer/WIDESEA_Core/Extensions/SwaggerSetup.cs | 131 +++++++++++++++++++++++++++++++++++++++++++
1 files changed, 131 insertions(+), 0 deletions(-)
diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Extensions/SwaggerSetup.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Extensions/SwaggerSetup.cs"
new file mode 100644
index 0000000..30c52f8
--- /dev/null
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Extensions/SwaggerSetup.cs"
@@ -0,0 +1,131 @@
+锘�
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.OpenApi.Models;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+using System.Threading.Tasks;
+using WIDESEA_Core.Helper;
+using static WIDESEA_Core.Extensions.CustomApiVersion;
+using Swashbuckle.AspNetCore.Filters;
+
+namespace WIDESEA_Core.Extensions
+{
+ /// <summary>
+ /// Swagger
+ /// </summary>
+ public static class SwaggerSetup
+ {
+ /// <summary>
+ /// Swagger
+ /// </summary>
+ /// <param name="services"></param>
+ /// <exception cref="ArgumentNullException"></exception>
+ public static void AddSwaggerSetup(this IServiceCollection services)
+ {
+ if (services == null) throw new ArgumentNullException(nameof(services));
+
+ var basePath = AppContext.BaseDirectory;
+ //var basePath2 = Microsoft.DotNet.PlatformAbstractions.ApplicationEnvironment.ApplicationBasePath;
+ var ApiName = AppSettings.app(new string[] { "ApiName" });
+
+ services.AddSwaggerGen(c =>
+ {
+ //閬嶅巻鍑哄叏閮ㄧ殑鐗堟湰锛屽仛鏂囨。淇℃伅灞曠ず
+ typeof(ApiVersions).GetEnumNames().ToList().ForEach(version =>
+ {
+ c.SwaggerDoc(version, new OpenApiInfo
+ {
+ Version = version,
+ Title = $"{ApiName} 鎺ュ彛鏂囨。鈥斺�攞RuntimeInformation.FrameworkDescription}",
+ Description = $"{ApiName} HTTP API " + version,
+ //Contact = new OpenApiContact { Name = ApiName, Email = "Blog.Core@xxx.com", Url = new Uri("https://neters.club") },
+ //License = new OpenApiLicense { Name = ApiName + " 瀹樻柟鏂囨。", Url = new Uri("http://apk.neters.club/.doc/") }
+ });
+ //c.OrderActionsBy(o => o.RelativePath);
+ });
+
+ c.UseInlineDefinitionsForEnums();
+ try
+ {
+ //杩欎釜灏辨槸鍒氬垰閰嶇疆鐨剎ml鏂囦欢鍚�
+ //var xmlPath = Path.Combine(basePath, "Blog.Core.xml");
+ //榛樿鐨勭浜屼釜鍙傛暟鏄痜alse锛岃繖涓槸controller鐨勬敞閲婏紝璁板緱淇敼
+ //c.IncludeXmlComments(xmlPath, true);
+
+ //杩欎釜灏辨槸Model灞傜殑xml鏂囦欢鍚�
+ //var xmlModelPath = Path.Combine(basePath, "Blog.Core.Model.xml");
+ //c.IncludeXmlComments(xmlModelPath);
+ }
+ catch (Exception ex)
+ {
+ //log.Error("Blog.Core.xml鍜孊log.Core.Model.xml 涓㈠け锛岃妫�鏌ュ苟鎷疯礉銆俓n" + ex.Message);
+ }
+
+ // 寮�鍚姞鏉冨皬閿�
+ c.OperationFilter<AddResponseHeadersFilter>();
+ c.OperationFilter<AppendAuthorizeToSummaryOperationFilter>();
+
+ // 鍦╤eader涓坊鍔爐oken锛屼紶閫掑埌鍚庡彴
+ //c.OperationFilter<SecurityRequirementsOperationFilter>();
+
+ c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
+ {
+ Description = "JWT鎺堟潈token鍓嶉潰闇�瑕佸姞涓婂瓧娈礏earer涓庝竴涓┖鏍�,濡侭earer token",
+ Name = "Authorization",
+ In = ParameterLocation.Header,
+ Type = SecuritySchemeType.ApiKey,
+ BearerFormat = "JWT",
+ Scheme = "Bearer"
+ });
+
+ c.AddSecurityRequirement(new OpenApiSecurityRequirement
+ {
+ {
+ new OpenApiSecurityScheme
+ {
+ Reference = new OpenApiReference {
+ Type = ReferenceType.SecurityScheme,
+ Id = "Bearer"
+ }
+ },
+ new string[] { }
+ }
+ });
+ }).AddControllers()
+ .ConfigureApiBehaviorOptions(options =>
+ {
+ options.SuppressConsumesConstraintForFormFileParameters = true;
+ options.SuppressInferBindingSourcesForParameters = true;
+ options.SuppressModelStateInvalidFilter = true;
+ options.SuppressMapClientErrors = true;
+ options.ClientErrorMapping[404].Link =
+ "https://*/404";
+ });
+ //services.AddSwaggerGenNewtonsoftSupport();
+ }
+ }
+
+ /// <summary>
+ /// 鑷畾涔夌増鏈�
+ /// </summary>
+ public class CustomApiVersion
+ {
+ /// <summary>
+ /// Api鎺ュ彛鐗堟湰 鑷畾涔�
+ /// </summary>
+ public enum ApiVersions
+ {
+ /// <summary>
+ /// V1 鐗堟湰
+ /// </summary>
+ V1 = 1,
+ /// <summary>
+ /// V2 鐗堟湰
+ /// </summary>
+ V2 = 2,
+ }
+ }
+}
--
Gitblit v1.9.3