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, ApplicationApiDescriptionModel applicationModel,
ApplicationApiDescriptionModelRequestDto input) ApplicationApiDescriptionModelRequestDto input)
{ {
var controllerType = apiDescription.ActionDescriptor.AsControllerActionDescriptor().ControllerTypeInfo.AsType(); var controllerType = apiDescription
.ActionDescriptor
.AsControllerActionDescriptor()
.ControllerTypeInfo;
var setting = FindSetting(controllerType); 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(); var method = apiDescription.ActionDescriptor.GetMethodInfo();
@ -86,13 +98,16 @@ namespace Volo.Abp.AspNetCore.Mvc
Logger.LogDebug($"ActionApiDescriptionModel.Create: {controllerModel.ControllerName}.{uniqueMethodName}"); Logger.LogDebug($"ActionApiDescriptionModel.Create: {controllerModel.ControllerName}.{uniqueMethodName}");
var actionModel = controllerModel.AddAction(uniqueMethodName, ActionApiDescriptionModel.Create( var actionModel = controllerModel.AddAction(
uniqueMethodName, uniqueMethodName,
method, ActionApiDescriptionModel.Create(
apiDescription.RelativePath, uniqueMethodName,
apiDescription.HttpMethod, method,
GetSupportedVersions(controllerType, method, setting) apiDescription.RelativePath,
)); apiDescription.HttpMethod,
GetSupportedVersions(controllerType, method, setting)
)
);
if (input.IncludeTypes) if (input.IncludeTypes)
{ {
@ -188,16 +203,16 @@ namespace Volo.Abp.AspNetCore.Mvc
return; 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; return;
} }
if (TypeHelper.IsDictionary(type, out var keyType, out var valueType)) if (TypeHelper.IsEnumerable(type, out var itemType))
{ {
AddCustomTypesToModel(applicationModel, keyType); AddCustomTypesToModel(applicationModel, itemType);
AddCustomTypesToModel(applicationModel, valueType);
return; 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, Name = parameterInfo.Name,
TypeAsString = parameterInfo.ParameterType.GetFullNameWithAssemblyName(), TypeAsString = parameterInfo.ParameterType.GetFullNameWithAssemblyName(),
Type = parameterInfo.ParameterType != null ? TypeHelper.GetFullNameHandlingNullableAndGenerics(parameterInfo.ParameterType) : null, Type = TypeHelper.GetFullNameHandlingNullableAndGenerics(parameterInfo.ParameterType),
TypeSimple = parameterInfo.ParameterType != null ? TypeHelper.GetSimplifiedName(parameterInfo.ParameterType) : null, TypeSimple = TypeHelper.GetSimplifiedName(parameterInfo.ParameterType),
IsOptional = parameterInfo.IsOptional, IsOptional = parameterInfo.IsOptional,
DefaultValue = parameterInfo.HasDefaultValue ? parameterInfo.DefaultValue : null 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 typeName;
string simpleTypeName; string simpleTypeName;
if (TypeHelper.IsEnumerable(propertyInfo.PropertyType, out var itemType, includePrimitives: false)) if (TypeHelper.IsDictionary(propertyInfo.PropertyType, out var keyType, out var valueType))
{
typeName = $"[{TypeHelper.GetFullNameHandlingNullableAndGenerics(itemType)}]";
simpleTypeName = $"[{TypeHelper.GetSimplifiedName(itemType)}]";
}
else if (TypeHelper.IsDictionary(propertyInfo.PropertyType, out var keyType, out var valueType))
{ {
typeName = $"{{{TypeHelper.GetFullNameHandlingNullableAndGenerics(keyType)}:{TypeHelper.GetFullNameHandlingNullableAndGenerics(valueType)}}}"; typeName = $"{{{TypeHelper.GetFullNameHandlingNullableAndGenerics(keyType)}:{TypeHelper.GetFullNameHandlingNullableAndGenerics(valueType)}}}";
simpleTypeName = $"{{{TypeHelper.GetSimplifiedName(keyType)}:{TypeHelper.GetSimplifiedName(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 else
{ {
typeName = TypeHelper.GetFullNameHandlingNullableAndGenerics(propertyInfo.PropertyType); typeName = TypeHelper.GetFullNameHandlingNullableAndGenerics(propertyInfo.PropertyType);
simpleTypeName = TypeHelper.GetSimplifiedName(propertyInfo.PropertyType); simpleTypeName = TypeHelper.GetSimplifiedName(propertyInfo.PropertyType);
} }
return new PropertyApiDescriptionModel return new PropertyApiDescriptionModel
{ {
Name = propertyInfo.Name, Name = propertyInfo.Name,
@ -43,4 +43,4 @@ namespace Volo.Abp.Http.Modeling
}; };
} }
} }
} }

Loading…
Cancel
Save