Browse Source

Properly handle dictionaries for API description model.

pull/4899/head
Halil İbrahim Kalkan 6 years ago
parent
commit
d04910fdb6
  1. 43
      framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs
  2. 6
      framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/MethodParameterApiDescriptionModel.cs
  3. 16
      framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/PropertyApiDescriptionModel.cs

43
framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs

@ -68,12 +68,24 @@ namespace Volo.Abp.AspNetCore.Mvc
ApplicationApiDescriptionModel applicationModel,
ApplicationApiDescriptionModelRequestDto input)
{
var controllerType = apiDescription.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.AsType();
var controllerType = apiDescription
.ActionDescriptor
.AsControllerActionDescriptor()
.ControllerTypeInfo;
var setting = FindSetting(controllerType);
var moduleModel = applicationModel.GetOrAddModule(GetRootPath(controllerType, setting), GetRemoteServiceName(controllerType, setting));
var moduleModel = applicationModel.GetOrAddModule(
GetRootPath(controllerType, setting),
GetRemoteServiceName(controllerType, setting)
);
var controllerModel = moduleModel.GetOrAddController(controllerType.FullName, CalculateControllerName(controllerType, setting), controllerType, _modelOptions.IgnoredInterfaces);
var controllerModel = moduleModel.GetOrAddController(
controllerType.FullName,
CalculateControllerName(controllerType, setting),
controllerType,
_modelOptions.IgnoredInterfaces
);
var method = apiDescription.ActionDescriptor.GetMethodInfo();
@ -86,13 +98,16 @@ namespace Volo.Abp.AspNetCore.Mvc
Logger.LogDebug($"ActionApiDescriptionModel.Create: {controllerModel.ControllerName}.{uniqueMethodName}");
var actionModel = controllerModel.AddAction(uniqueMethodName, ActionApiDescriptionModel.Create(
var actionModel = controllerModel.AddAction(
uniqueMethodName,
method,
apiDescription.RelativePath,
apiDescription.HttpMethod,
GetSupportedVersions(controllerType, method, setting)
));
ActionApiDescriptionModel.Create(
uniqueMethodName,
method,
apiDescription.RelativePath,
apiDescription.HttpMethod,
GetSupportedVersions(controllerType, method, setting)
)
);
if (input.IncludeTypes)
{
@ -188,16 +203,16 @@ namespace Volo.Abp.AspNetCore.Mvc
return;
}
if (TypeHelper.IsEnumerable(type, out var itemType))
if (TypeHelper.IsDictionary(type, out var keyType, out var valueType))
{
AddCustomTypesToModel(applicationModel, itemType);
AddCustomTypesToModel(applicationModel, keyType);
AddCustomTypesToModel(applicationModel, valueType);
return;
}
if (TypeHelper.IsDictionary(type, out var keyType, out var valueType))
if (TypeHelper.IsEnumerable(type, out var itemType))
{
AddCustomTypesToModel(applicationModel, keyType);
AddCustomTypesToModel(applicationModel, valueType);
AddCustomTypesToModel(applicationModel, itemType);
return;
}

6
framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/MethodParameterApiDescriptionModel.cs

@ -30,11 +30,11 @@ namespace Volo.Abp.Http.Modeling
{
Name = parameterInfo.Name,
TypeAsString = parameterInfo.ParameterType.GetFullNameWithAssemblyName(),
Type = parameterInfo.ParameterType != null ? TypeHelper.GetFullNameHandlingNullableAndGenerics(parameterInfo.ParameterType) : null,
TypeSimple = parameterInfo.ParameterType != null ? TypeHelper.GetSimplifiedName(parameterInfo.ParameterType) : null,
Type = TypeHelper.GetFullNameHandlingNullableAndGenerics(parameterInfo.ParameterType),
TypeSimple = TypeHelper.GetSimplifiedName(parameterInfo.ParameterType),
IsOptional = parameterInfo.IsOptional,
DefaultValue = parameterInfo.HasDefaultValue ? parameterInfo.DefaultValue : null
};
}
}
}
}

16
framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/PropertyApiDescriptionModel.cs

@ -19,22 +19,22 @@ namespace Volo.Abp.Http.Modeling
string typeName;
string simpleTypeName;
if (TypeHelper.IsEnumerable(propertyInfo.PropertyType, out var itemType, includePrimitives: false))
{
typeName = $"[{TypeHelper.GetFullNameHandlingNullableAndGenerics(itemType)}]";
simpleTypeName = $"[{TypeHelper.GetSimplifiedName(itemType)}]";
}
else if (TypeHelper.IsDictionary(propertyInfo.PropertyType, out var keyType, out var valueType))
if (TypeHelper.IsDictionary(propertyInfo.PropertyType, out var keyType, out var valueType))
{
typeName = $"{{{TypeHelper.GetFullNameHandlingNullableAndGenerics(keyType)}:{TypeHelper.GetFullNameHandlingNullableAndGenerics(valueType)}}}";
simpleTypeName = $"{{{TypeHelper.GetSimplifiedName(keyType)}:{TypeHelper.GetSimplifiedName(valueType)}}}";
}
else if (TypeHelper.IsEnumerable(propertyInfo.PropertyType, out var itemType, includePrimitives: false))
{
typeName = $"[{TypeHelper.GetFullNameHandlingNullableAndGenerics(itemType)}]";
simpleTypeName = $"[{TypeHelper.GetSimplifiedName(itemType)}]";
}
else
{
typeName = TypeHelper.GetFullNameHandlingNullableAndGenerics(propertyInfo.PropertyType);
simpleTypeName = TypeHelper.GetSimplifiedName(propertyInfo.PropertyType);
}
return new PropertyApiDescriptionModel
{
Name = propertyInfo.Name,
@ -43,4 +43,4 @@ namespace Volo.Abp.Http.Modeling
};
}
}
}
}

Loading…
Cancel
Save