|
|
|
@ -3,6 +3,7 @@ using System.Linq; |
|
|
|
using Microsoft.AspNetCore.Mvc; |
|
|
|
using Microsoft.AspNetCore.Mvc.Abstractions; |
|
|
|
using Microsoft.AspNetCore.Mvc.ApiExplorer; |
|
|
|
using Microsoft.AspNetCore.Mvc.Controllers; |
|
|
|
using Microsoft.AspNetCore.Mvc.Formatters; |
|
|
|
using Microsoft.AspNetCore.Mvc.ModelBinding; |
|
|
|
using Microsoft.Extensions.Options; |
|
|
|
@ -19,7 +20,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApiExploring |
|
|
|
|
|
|
|
public AbpRemoteServiceApiDescriptionProvider( |
|
|
|
IModelMetadataProvider modelMetadataProvider, |
|
|
|
IOptions<MvcOptions> mvcOptionsAccessor, |
|
|
|
IOptions<MvcOptions> mvcOptionsAccessor, |
|
|
|
IOptions<AbpRemoteServiceApiDescriptionProviderOptions> optionsAccessor) |
|
|
|
{ |
|
|
|
_modelMetadataProvider = modelMetadataProvider; |
|
|
|
@ -41,7 +42,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApiExploring |
|
|
|
{ |
|
|
|
foreach (var apiResponseType in GetApiResponseTypes()) |
|
|
|
{ |
|
|
|
foreach (var result in context.Results.Where(x => IsRemoteService(x.ActionDescriptor))) |
|
|
|
foreach (var result in context.Results.Where(IsRemoteService)) |
|
|
|
{ |
|
|
|
var actionProducesResponseTypeAttributes = |
|
|
|
ReflectionHelper.GetAttributesOfMemberOrDeclaringType<ProducesResponseTypeAttribute>( |
|
|
|
@ -62,7 +63,7 @@ namespace Volo.Abp.AspNetCore.Mvc.ApiExploring |
|
|
|
foreach (var apiResponse in _options.SupportedResponseTypes) |
|
|
|
{ |
|
|
|
apiResponse.ModelMetadata = _modelMetadataProvider.GetMetadataForType(apiResponse.Type); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var responseTypeMetadataProvider in _mvcOptions.OutputFormatters.OfType<IApiResponseTypeMetadataProvider>()) |
|
|
|
{ |
|
|
|
var formatterSupportedContentTypes = responseTypeMetadataProvider.GetSupportedContentTypes(null, apiResponse.Type); |
|
|
|
@ -85,10 +86,29 @@ namespace Volo.Abp.AspNetCore.Mvc.ApiExploring |
|
|
|
return _options.SupportedResponseTypes; |
|
|
|
} |
|
|
|
|
|
|
|
protected virtual bool IsRemoteService(ActionDescriptor actionDescriptor) |
|
|
|
protected virtual bool IsRemoteService(ApiDescription actionDescriptor) |
|
|
|
{ |
|
|
|
var remoteServiceAttr = ReflectionHelper.GetSingleAttributeOfMemberOrDeclaringTypeOrDefault<RemoteServiceAttribute>(actionDescriptor.GetMethodInfo()); |
|
|
|
return remoteServiceAttr != null && remoteServiceAttr.IsEnabled; |
|
|
|
if (actionDescriptor.ActionDescriptor is ControllerActionDescriptor controllerActionDescriptor) |
|
|
|
{ |
|
|
|
var remoteServiceAttr = ReflectionHelper.GetSingleAttributeOfMemberOrDeclaringTypeOrDefault<RemoteServiceAttribute>(controllerActionDescriptor.MethodInfo); |
|
|
|
if (remoteServiceAttr != null && remoteServiceAttr.IsEnabled) |
|
|
|
{ |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
remoteServiceAttr = ReflectionHelper.GetSingleAttributeOfMemberOrDeclaringTypeOrDefault<RemoteServiceAttribute>(controllerActionDescriptor.ControllerTypeInfo); |
|
|
|
if (remoteServiceAttr != null && remoteServiceAttr.IsEnabled) |
|
|
|
{ |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
if (typeof(IRemoteService).IsAssignableFrom(controllerActionDescriptor.ControllerTypeInfo)) |
|
|
|
{ |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|