0
apiプラグインに新しいメソッドを追加すると、nopCommerce webApiプラグインで作業しています。 たとえば、製品のAPIコントローラにGetTest()メソッドを追加します。 swaggerUIに表示されるメソッドのリストには表示されません。NopCommerceのカスタムAPIメソッドがswaggerUiに表示されない
GetTest()メソッドはSwaggerUi Listでは使用できません。
私もstartup.csでWeb 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を私に案内してください。
いくつかの理由が考えられます。あなたのスタートアップがスワッガーを正しく設定していません。そのクラスには全く同じ名前のメソッドが重複しています。 – lloyd
@lloyd SwaggerUiの設定を追加しました。 と、ProductsControllerにGetTestのメソッドが1つしかありません。 –