2017-11-30 11 views
0

apiプラグインに新しいメソッドを追加すると、nopCommerce webApiプラグインで作業しています。 たとえば、製品のAPIコントローラにGetTest()メソッドを追加します。 swaggerUIに表示されるメソッドのリストには表示されません。NopCommerceのカスタムAPIメソッドがswaggerUiに表示されない

GetTest()メソッドはSwaggerUi Listでは使用できません。

enter image description here

私もstartup.csでWeb APIのルートを追加しました。

enter image description here

は、ここに私のAPI GetTest()方法です。ここ

enter image description here

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を私に案内してください。

+0

いくつかの理由が考えられます。あなたのスタートアップがスワッガーを正しく設定していません。そのクラスには全く同じ名前のメソッドが重複しています。 – lloyd

+0

@lloyd SwaggerUiの設定を追加しました。 と、ProductsControllerにGetTestのメソッドが1つしかありません。 –

答えて

0

は、他のすべてのHTTPGET方法が

などを持っているように応答タイプを追加してください。

[ResponseType(typeof(MyTestResult))] 

これはテストできませんでしたが、これは既存の方法との唯一の違いと思われます。

関連する問題