0
api 플러그인에 새 메소드를 추가 할 때 nopCommerce webApi 플러그인에 대한 작업을하고 있습니다. 예를 들어, 제품 컨트롤러에 GetTest() 메서드를 추가합니다. swaggerUI에 표시되는 메소드 목록에는 표시되지 않습니다.NopCommerce 사용자 정의 api 메소드가 swaggerUi에 표시되지 않습니다.
GetTest() 메서드는 SwaggerUi List에서 사용할 수 없습니다.
나는 또한 startup.cs의 웹 API 경로를 추가했습니다.은 여기 내 API를 GetTest() 방법이다.
여기 Startup.cs 내 SwaggerUi 구성입니다.
config.Filters.Add(new ServerErrorHandlerAttribute());
config.Formatters.JsonFormatter.SerializerSettings = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore
};
config.Routes.MapHttpRoute(
name: "GetTest",
routeTemplate: "api/products/GetTest",
defaults: new { controller = "Products", action = "GetTest" });
// The default route templates for the Swagger docs and swagger-ui are "swagger/docs/{apiVersion}" and "swagger/ui/index#/{assetPath}" respectively.
config
.EnableSwagger(c =>
{
c.SingleApiVersion("v1", "RESTful API documentation");
c.IncludeXmlComments(string.Format(@"{0}\Plugins\Nop.Plugin.Api\Nop.Plugin.Api.XML", AppDomain.CurrentDomain.BaseDirectory));
// We need this filter to exclude some of the API endpoints from the documentation i.e /OAuth/Authorize endpoint
c.DocumentFilter<ExcludeEnpointsDocumentFilter>();
c.OperationFilter<RemovePrefixesOperationFilter>();
c.OperationFilter<ChangeParameterTypeOperationFilter>();
})
.EnableSwaggerUi(c =>
{
var currentAssembly = Assembly.GetAssembly(this.GetType());
var currentAssemblyName = currentAssembly.GetName().Name;
c.InjectJavaScript(currentAssembly, string.Format("{0}.Scripts.swaggerPostPutTryItOutButtonsRemoval.js", currentAssemblyName));
});
app.UseWebApi(config);
config.DependencyResolver = new AutofacWebApiDependencyResolver(EngineContext.Current.ContainerManager.Container);
// Configure the asp.net webhooks.
ConfigureWebhooks(config);
조금만 안내해주세요. SwaggerUI에 처음 오 셨습니다.
몇 가지 이유가있을 수 있습니다. 시작 프로그램이 swagger를 올바르게 구성하지 않습니다. 해당 클래스에는 정확히 같은 이름의 중복 메소드가 있습니다. – lloyd
@lloyd SwaggerUi의 구성을 추가했습니다. 모양은 이고 ProductsController에는 GetTest의 단 하나의 메소드 만 있습니다. –