API Versioning improvements.

pull/122/head
Halil İbrahim Kalkan 7 years ago
parent e2496b87cc
commit 1df5821fb6

@ -12,10 +12,12 @@ using Volo.Abp.DependencyInjection;
using Volo.Abp.Modularity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Controllers;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Mvc.ViewComponents;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Volo.Abp.Http;
using Volo.Abp.Http.Modeling;
namespace Volo.Abp.AspNetCore.Mvc
{
@ -41,6 +43,21 @@ namespace Volo.Abp.AspNetCore.Mvc
)
)
);
services.Configure<ApiDescriptionModelOptions>(options =>
{
options.IgnoredInterfaces.AddIfNotContains(typeof(IAsyncActionFilter));
options.IgnoredInterfaces.AddIfNotContains(typeof(IFilterMetadata));
options.IgnoredInterfaces.AddIfNotContains(typeof(IActionFilter));
});
services.Configure<AbpAspNetCoreMvcOptions>(options =>
{
options.AppServiceControllers.Create(typeof(AbpAspNetCoreMvcModule).Assembly, o =>
{
o.RootPath = "abp";
});
});
}
public override void PostConfigureServices(IServiceCollection services)

@ -46,8 +46,7 @@ namespace Volo.Abp.AspNetCore.Mvc
public List<ApiVersion> ApiVersions { get; set; }
public Action<ApiVersioningOptions> ApiVersionConfigurer { get; set; }
public AbpControllerAssemblySetting([NotNull] Assembly assembly, [NotNull] string rootPath)
{
Check.NotNull(assembly, rootPath);

@ -1,10 +1,11 @@
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.Application.Services;
using Volo.Abp.Http.Modeling;
namespace Volo.Abp.AspNetCore.Mvc.ApiExploring
{
[Route("api/abp/api-description")]
public class AbpApiDefinitionController : AbpController
[Route("api/abp/api-definition")]
public class AbpApiDefinitionController : AbpController, IRemoteService
{
private readonly IApiDescriptionModelProvider _modelProvider;

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
@ -9,7 +10,6 @@ using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using Volo.Abp.Application.Services;
using Volo.Abp.AspNetCore.Mvc.Utils;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Http.Modeling;
@ -22,13 +22,16 @@ namespace Volo.Abp.AspNetCore.Mvc
private readonly IApiDescriptionGroupCollectionProvider _descriptionProvider;
private readonly AbpAspNetCoreMvcOptions _options;
private readonly ApiDescriptionModelOptions _modelOptions;
public AspNetCoreApiDescriptionModelProvider(
IApiDescriptionGroupCollectionProvider descriptionProvider,
IOptions<AbpAspNetCoreMvcOptions> options)
IOptions<AbpAspNetCoreMvcOptions> options,
IOptions<ApiDescriptionModelOptions> modelOptions)
{
_descriptionProvider = descriptionProvider;
_options = options.Value;
_modelOptions = modelOptions.Value;
Logger = NullLogger<AspNetCoreApiDescriptionModelProvider>.Instance;
}
@ -59,7 +62,7 @@ namespace Volo.Abp.AspNetCore.Mvc
var moduleModel = model.GetOrAddModule(GetRootPath(controllerType));
var controllerModel = moduleModel.GetOrAddController(GetControllerName(apiDescription), controllerType);
var controllerModel = moduleModel.GetOrAddController(controllerType.FullName, controllerType, _modelOptions.IgnoredInterfaces);
var method = apiDescription.ActionDescriptor.GetMethodInfo();
@ -80,12 +83,6 @@ namespace Volo.Abp.AspNetCore.Mvc
AddParameterDescriptionsToModel(actionModel, method, apiDescription);
}
private static string GetControllerName(ApiDescription apiDescription)
{
return apiDescription.GroupName?.RemovePostFix(ApplicationService.CommonPostfixes)
?? apiDescription.ActionDescriptor.AsControllerActionDescriptor().ControllerName;
}
private static string GetUniqueActionName(MethodInfo method)
{
var methodNameBuilder = new StringBuilder(method.Name);

@ -42,7 +42,7 @@ namespace Volo.Abp.Http.Client.DynamicProxying
{
using (var client = _httpClientFactory.Create())
{
var response = await client.GetAsync(baseUrl + "api/abp/api-description");
var response = await client.GetAsync(baseUrl + "api/abp/api-definition");
if (!response.IsSuccessStatusCode)
{
throw new AbpException("Remote service returns error!");

@ -28,7 +28,7 @@ namespace Volo.Abp.Http.Modeling
}
public static ActionApiDescriptionModel Create(MethodInfo method, string uniqueName, string url, string httpMethod = null)
public static ActionApiDescriptionModel Create(MethodInfo method, string uniqueName, string url, string httpMethod)
{
return new ActionApiDescriptionModel
{

@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using Volo.Abp.Application.Services;
using Volo.Abp.Aspects;
using Volo.Abp.DependencyInjection;
namespace Volo.Abp.Http.Modeling
{
public class ApiDescriptionModelOptions
{
public HashSet<Type> IgnoredInterfaces { get; }
public ApiDescriptionModelOptions()
{
IgnoredInterfaces = new HashSet<Type>
{
typeof(IApplicationService),
typeof(IRemoteService),
typeof(ITransientDependency),
typeof(ISingletonDependency),
typeof(IDisposable),
typeof(IAvoidDuplicateCrossCuttingConcerns)
};
}
}
}

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
namespace Volo.Abp.Http.Modeling
{
@ -20,7 +21,7 @@ namespace Volo.Abp.Http.Modeling
}
public static ControllerApiDescriptionModel Create(string controllerName, Type type)
public static ControllerApiDescriptionModel Create(string controllerName, Type type, [CanBeNull] HashSet<Type> ignoredInterfaces = null)
{
return new ControllerApiDescriptionModel
{
@ -29,6 +30,7 @@ namespace Volo.Abp.Http.Modeling
Actions = new Dictionary<string, ActionApiDescriptionModel>(),
Interfaces = type
.GetInterfaces()
.WhereIf(ignoredInterfaces != null, i => !i.IsGenericType && !ignoredInterfaces.Contains(i))
.Select(ControllerInterfaceApiDescriptionModel.Create)
.ToList()
};

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
namespace Volo.Abp.Http.Modeling
{
@ -40,9 +41,9 @@ namespace Volo.Abp.Http.Modeling
return Controllers[controller.ControllerName] = controller;
}
public ControllerApiDescriptionModel GetOrAddController(string name, Type type)
public ControllerApiDescriptionModel GetOrAddController(string name, Type type, [CanBeNull] HashSet<Type> ignoredInterfaces = null)
{
return Controllers.GetOrAdd(name, () => ControllerApiDescriptionModel.Create(name, type));
return Controllers.GetOrAdd(name, () => ControllerApiDescriptionModel.Create(name, type, ignoredInterfaces));
}
public ModuleApiDescriptionModel CreateSubModel(string[] controllers, string[] actions)

@ -1,14 +1,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ApiExplorer;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.AspNetCore.Mvc.RazorPages.Internal;
using Microsoft.AspNetCore.Mvc.Versioning;
using Microsoft.AspNetCore.Mvc.Versioning.Conventions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Examples;
using Microsoft.Extensions.Configuration;
@ -16,7 +9,6 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Swashbuckle.AspNetCore.Swagger;
using Volo.Abp.AspNetCore.Modularity;
using Volo.Abp.AspNetCore.Mvc.ApiExploring;
using Volo.Abp.Autofac;
using Volo.Abp.Data;
using Volo.Abp.EntityFrameworkCore;
@ -58,7 +50,6 @@ namespace Volo.Abp.Identity.HttpApi.Host
services.AddApiVersioning(o =>
{
o.ReportApiVersions = true;
o.Conventions.Controller<AbpApiDefinitionController>().IsApiVersionNeutral(); //TODO: This should be inside the framework!
//o.Conventions.Controller<AbpApiDefinitionController>().Action((MethodInfo)null).MapToApiVersion(new ApiVersion(1,1),).IsApiVersionNeutral();
//o.Conventions.Controller<AbpApiDefinitionController>().HasApiVersion(new ApiVersion(3, 0)); //We can do that based on controller's AbpApiVersion attribute!
o.AssumeDefaultVersionWhenUnspecified = true;

@ -6,7 +6,6 @@ namespace Volo.Abp.Identity.HttpApi.Host.Controllers
public class HomeController : AbpController
{
[HttpPost]
[Route("/api/v1/users/create")]
public IActionResult Index()
{
return Redirect("/swagger");

Loading…
Cancel
Save