2017-11-30 14 views
0

api 플러그인에 새 메소드를 추가 할 때 nopCommerce webApi 플러그인에 대한 작업을하고 있습니다. 예를 들어, 제품 컨트롤러에 GetTest() 메서드를 추가합니다. swaggerUI에 표시되는 메소드 목록에는 표시되지 않습니다.NopCommerce 사용자 정의 api 메소드가 swaggerUi에 표시되지 않습니다.

GetTest() 메서드는 SwaggerUi List에서 사용할 수 없습니다.

enter image description here

나는 또한 startup.cs의 웹 API 경로를 추가했습니다.

enter image description here

은 여기 내 API를 GetTest() 방법이다.

enter image description here

여기 Startup.csSwaggerUi 구성입니다.

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에 처음 오 셨습니다.

+0

몇 가지 이유가있을 수 있습니다. 시작 프로그램이 swagger를 올바르게 구성하지 않습니다. 해당 클래스에는 정확히 같은 이름의 중복 메소드가 있습니다. – lloyd

+0

@lloyd SwaggerUi의 구성을 추가했습니다. 모양은 이고 ProductsController에는 GetTest의 단 하나의 메소드 만 있습니다. –

답변

0

는 방법이

예를 들어,이 모든 다른 HttpGet 같은 응답 유형을 추가하려고합니다.

[ResponseType(typeof(MyTestResult))] 

이 방법은 테스트 할 수 없었지만 기존 방법과 유일한 차이점이있는 것으로 보입니다.