Enable nullable annotations for Volo.Abp.Http

pull/17560/head
liangshiwei 2 years ago
parent 106d510561
commit 95ae085c20

@ -145,7 +145,7 @@ public class AspNetCoreApiDescriptionModelProvider : IApiDescriptionModelProvide
ActionApiDescriptionModel.Create(
uniqueMethodName,
method,
apiDescription.RelativePath,
apiDescription.RelativePath!,
apiDescription.HttpMethod,
GetSupportedVersions(controllerType, method, setting),
allowAnonymous,

@ -32,7 +32,7 @@ public class ServiceProxyGenerationModel
public ProxyScriptingModel CreateOptions()
{
var options = new ProxyScriptingModel(Type, UseCache);
var options = new ProxyScriptingModel(Type!, UseCache);
if (!Modules.IsNullOrEmpty())
{

@ -5,6 +5,8 @@
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net7.0</TargetFrameworks>
<Nullable>enable</Nullable>
<WarningsAsErrors>Nullable</WarningsAsErrors>
<AssemblyName>Volo.Abp.Http</AssemblyName>
<PackageId>Volo.Abp.Http</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>

@ -43,12 +43,12 @@ public static class HttpMethodHelper
return methodName;
}
return methodName.RemovePreFix(prefixes);
return methodName.RemovePreFix(prefixes!);
}
public static HttpMethod ConvertToHttpMethod(string httpMethod)
public static HttpMethod ConvertToHttpMethod(string? httpMethod)
{
switch (httpMethod.ToUpperInvariant())
switch (httpMethod?.ToUpperInvariant())
{
case "GET":
return HttpMethod.Get;

@ -10,32 +10,32 @@ namespace Volo.Abp.Http.Modeling;
[Serializable]
public class ActionApiDescriptionModel
{
public string UniqueName { get; set; }
public string UniqueName { get; set; } = default!;
public string Name { get; set; }
public string Name { get; set; } = default!;
public string HttpMethod { get; set; }
public string? HttpMethod { get; set; }
public string Url { get; set; }
public string Url { get; set; } = default!;
public IList<string> SupportedVersions { get; set; }
public IList<string>? SupportedVersions { get; set; }
public IList<MethodParameterApiDescriptionModel> ParametersOnMethod { get; set; }
public IList<MethodParameterApiDescriptionModel> ParametersOnMethod { get; set; } = default!;
public IList<ParameterApiDescriptionModel> Parameters { get; set; }
public IList<ParameterApiDescriptionModel> Parameters { get; set; } = default!;
public ReturnValueApiDescriptionModel ReturnValue { get; set; }
public ReturnValueApiDescriptionModel ReturnValue { get; set; } = default!;
public bool? AllowAnonymous { get; set; }
public string ImplementFrom { get; set; }
public string? ImplementFrom { get; set; }
public ActionApiDescriptionModel()
{
}
public static ActionApiDescriptionModel Create([NotNull] string uniqueName, [NotNull] MethodInfo method, [NotNull] string url, [CanBeNull] string httpMethod, [NotNull] IList<string> supportedVersions, bool? allowAnonymous = null, string implementFrom = null)
public static ActionApiDescriptionModel Create([NotNull] string uniqueName, [NotNull] MethodInfo method, [NotNull] string url, string? httpMethod, [NotNull] IList<string> supportedVersions, bool? allowAnonymous = null, string? implementFrom = null)
{
Check.NotNull(uniqueName, nameof(uniqueName));
Check.NotNull(method, nameof(method));

@ -17,16 +17,16 @@ public static class ApiTypeNameHelper
if (TypeHelper.IsDictionary(type, out var keyType, out var valueType))
{
if (!duplicateTypes.Contains(keyType) && !duplicateTypes.Contains(valueType))
if (!duplicateTypes.Contains(keyType!) && !duplicateTypes.Contains(valueType!))
{
return $"{{{GetTypeName(keyType, duplicateTypes)}:{GetTypeName(valueType, duplicateTypes)}}}";
return $"{{{GetTypeName(keyType!, duplicateTypes)}:{GetTypeName(valueType!, duplicateTypes)}}}";
}
}
else if (TypeHelper.IsEnumerable(type, out var itemType, includePrimitives: false))
{
if (!duplicateTypes.Contains(itemType))
if (!duplicateTypes.Contains(itemType!))
{
return $"[{GetTypeName(itemType, duplicateTypes)}]";
return $"[{GetTypeName(itemType!, duplicateTypes)}]";
}
}
@ -44,16 +44,16 @@ public static class ApiTypeNameHelper
if (TypeHelper.IsDictionary(type, out var keyType, out var valueType))
{
if (!duplicateTypes.Contains(keyType) && !duplicateTypes.Contains(valueType))
if (!duplicateTypes.Contains(keyType!) && !duplicateTypes.Contains(valueType!))
{
return $"{{{GetSimpleTypeName(keyType, duplicateTypes)}:{GetSimpleTypeName(valueType, duplicateTypes)}}}";
return $"{{{GetSimpleTypeName(keyType!, duplicateTypes)}:{GetSimpleTypeName(valueType!, duplicateTypes)}}}";
}
}
else if (TypeHelper.IsEnumerable(type, out var itemType, includePrimitives: false))
{
if (!duplicateTypes.Contains(itemType))
if (!duplicateTypes.Contains(itemType!))
{
return $"[{GetSimpleTypeName(itemType, duplicateTypes)}]";
return $"[{GetSimpleTypeName(itemType!, duplicateTypes)}]";
}
}

@ -8,9 +8,9 @@ namespace Volo.Abp.Http.Modeling;
[Serializable]
public class ApplicationApiDescriptionModel
{
public IDictionary<string, ModuleApiDescriptionModel> Modules { get; set; }
public IDictionary<string, ModuleApiDescriptionModel> Modules { get; set; } = default!;
public IDictionary<string, TypeApiDescriptionModel> Types { get; set; }
public IDictionary<string, TypeApiDescriptionModel> Types { get; set; } = default!;
public ApplicationApiDescriptionModel()
{
@ -41,7 +41,7 @@ public class ApplicationApiDescriptionModel
return Modules.GetOrAdd(rootPath, () => ModuleApiDescriptionModel.Create(rootPath, remoteServiceName));
}
public ApplicationApiDescriptionModel CreateSubModel(string[] modules = null, string[] controllers = null, string[] actions = null)
public ApplicationApiDescriptionModel CreateSubModel(string[]? modules = null, string[]? controllers = null, string[]? actions = null)
{
var subModel = ApplicationApiDescriptionModel.Create(); ;

@ -8,28 +8,28 @@ namespace Volo.Abp.Http.Modeling;
[Serializable]
public class ControllerApiDescriptionModel
{
public string ControllerName { get; set; }
public string ControllerName { get; set; } = default!;
public string ControllerGroupName { get; set; }
public string? ControllerGroupName { get; set; }
public bool IsRemoteService { get; set; }
public bool IsIntegrationService { get; set; }
public string ApiVersion { get; set; }
public string? ApiVersion { get; set; }
public string Type { get; set; }
public string Type { get; set; } = default!;
public List<ControllerInterfaceApiDescriptionModel> Interfaces { get; set; }
public List<ControllerInterfaceApiDescriptionModel> Interfaces { get; set; } = default!;
public Dictionary<string, ActionApiDescriptionModel> Actions { get; set; }
public Dictionary<string, ActionApiDescriptionModel> Actions { get; set; } = default!;
public ControllerApiDescriptionModel()
{
}
public static ControllerApiDescriptionModel Create(string controllerName, string groupName, bool isRemoteService, bool isIntegrationService, string apiVersion, Type type, [CanBeNull] HashSet<Type> ignoredInterfaces = null)
public static ControllerApiDescriptionModel Create(string controllerName, string? groupName, bool isRemoteService, bool isIntegrationService, string? apiVersion, Type type, HashSet<Type>? ignoredInterfaces = null)
{
return new ControllerApiDescriptionModel
{
@ -38,11 +38,11 @@ public class ControllerApiDescriptionModel
IsRemoteService = isRemoteService,
IsIntegrationService = isIntegrationService, //IntegrationServiceAttribute.IsDefinedOrInherited(type),
ApiVersion = apiVersion,
Type = type.FullName,
Type = type.FullName!,
Actions = new Dictionary<string, ActionApiDescriptionModel>(),
Interfaces = type
.GetInterfaces()
.WhereIf(ignoredInterfaces != null, i => !i.IsGenericType && !ignoredInterfaces.Contains(i))
.WhereIf(ignoredInterfaces != null, i => !i.IsGenericType && !ignoredInterfaces!.Contains(i))
.Select(ControllerInterfaceApiDescriptionModel.Create)
.ToList()
};
@ -60,7 +60,7 @@ public class ControllerApiDescriptionModel
return Actions[uniqueName] = action;
}
public ControllerApiDescriptionModel CreateSubModel(string[] actions)
public ControllerApiDescriptionModel CreateSubModel(string[]? actions)
{
var subModel = new ControllerApiDescriptionModel
{

@ -8,11 +8,11 @@ namespace Volo.Abp.Http.Modeling;
[Serializable]
public class ControllerInterfaceApiDescriptionModel
{
public string Type { get; set; }
public string Type { get; set; } = default!;
public string Name { get; set; }
public string Name { get; set; } = default!;
public InterfaceMethodApiDescriptionModel[] Methods { get; set; }
public InterfaceMethodApiDescriptionModel[] Methods { get; set; } = default!;
public ControllerInterfaceApiDescriptionModel()
{
@ -23,7 +23,7 @@ public class ControllerInterfaceApiDescriptionModel
{
var model = new ControllerInterfaceApiDescriptionModel
{
Type = type.FullName,
Type = type.FullName!,
Name = type.Name
};

@ -9,11 +9,11 @@ namespace Volo.Abp.Http.Modeling;
[Serializable]
public class InterfaceMethodApiDescriptionModel
{
public string Name { get; set; }
public string Name { get; set; } = default!;
public IList<MethodParameterApiDescriptionModel> ParametersOnMethod { get; set; }
public IList<MethodParameterApiDescriptionModel> ParametersOnMethod { get; set; } = default!;
public ReturnValueApiDescriptionModel ReturnValue { get; set; }
public ReturnValueApiDescriptionModel ReturnValue { get; set; } = default!;
public InterfaceMethodApiDescriptionModel()
{

@ -7,17 +7,17 @@ namespace Volo.Abp.Http.Modeling;
[Serializable]
public class MethodParameterApiDescriptionModel
{
public string Name { get; set; }
public string Name { get; set; } = default!;
public string TypeAsString { get; set; }
public string TypeAsString { get; set; } = default!;
public string Type { get; set; }
public string Type { get; set; } = default!;
public string TypeSimple { get; set; }
public string TypeSimple { get; set; } = default!;
public bool IsOptional { get; set; }
public object DefaultValue { get; set; }
public object? DefaultValue { get; set; }
public MethodParameterApiDescriptionModel()
{
@ -28,7 +28,7 @@ public class MethodParameterApiDescriptionModel
{
return new MethodParameterApiDescriptionModel
{
Name = parameterInfo.Name,
Name = parameterInfo.Name!,
TypeAsString = parameterInfo.ParameterType.GetFullNameWithAssemblyName(),
Type = TypeHelper.GetFullNameHandlingNullableAndGenerics(parameterInfo.ParameterType),
TypeSimple = ApiTypeNameHelper.GetSimpleTypeName(parameterInfo.ParameterType),

@ -18,11 +18,11 @@ public class ModuleApiDescriptionModel
/// </summary>
public const string DefaultRemoteServiceName = "Default";
public string RootPath { get; set; }
public string RootPath { get; set; } = default!;
public string RemoteServiceName { get; set; }
public string RemoteServiceName { get; set; } = default!;
public IDictionary<string, ControllerApiDescriptionModel> Controllers { get; set; }
public IDictionary<string, ControllerApiDescriptionModel> Controllers { get; set; } = default!;
public ModuleApiDescriptionModel()
{
@ -49,13 +49,13 @@ public class ModuleApiDescriptionModel
return Controllers[controller.Type] = controller;
}
public ControllerApiDescriptionModel GetOrAddController(string name, string groupName, bool isRemoteService, bool isIntegrationService, string apiVersion, Type type, [CanBeNull] HashSet<Type> ignoredInterfaces = null)
public ControllerApiDescriptionModel GetOrAddController(string name, string? groupName, bool isRemoteService, bool isIntegrationService, string? apiVersion, Type type, HashSet<Type>? ignoredInterfaces = null)
{
var key = apiVersion.IsNullOrWhiteSpace() ? type.FullName : $"{apiVersion + "."}{type.FullName}";
var key = (apiVersion.IsNullOrWhiteSpace() ? type.FullName : $"{apiVersion + "."}{type.FullName}")!;
return Controllers.GetOrAdd(key, () => ControllerApiDescriptionModel.Create(name, groupName, isRemoteService, isIntegrationService, apiVersion, type, ignoredInterfaces));
}
public ModuleApiDescriptionModel CreateSubModel(string[] controllers, string[] actions)
public ModuleApiDescriptionModel CreateSubModel(string[]? controllers, string[]? actions)
{
var subModel = Create(RootPath, RemoteServiceName);

@ -6,32 +6,32 @@ namespace Volo.Abp.Http.Modeling;
[Serializable]
public class ParameterApiDescriptionModel
{
public string NameOnMethod { get; set; }
public string NameOnMethod { get; set; } = default!;
public string Name { get; set; }
public string Name { get; set; } = default!;
public string JsonName { get; set; }
public string? JsonName { get; set; }
public string Type { get; set; }
public string? Type { get; set; }
public string TypeSimple { get; set; }
public string? TypeSimple { get; set; }
public bool IsOptional { get; set; }
public object DefaultValue { get; set; }
public object? DefaultValue { get; set; }
public string[] ConstraintTypes { get; set; }
public string[]? ConstraintTypes { get; set; }
public string BindingSourceId { get; set; }
public string? BindingSourceId { get; set; }
public string DescriptorName { get; set; }
public string? DescriptorName { get; set; }
public ParameterApiDescriptionModel()
{
}
public static ParameterApiDescriptionModel Create(string name, string jsonName, string nameOnMethod, Type type, bool isOptional = false, object defaultValue = null, string[] constraintTypes = null, string bindingSourceId = null, string descriptorName = null)
public static ParameterApiDescriptionModel Create(string name, string? jsonName, string nameOnMethod, Type type, bool isOptional = false, object? defaultValue = null, string[]? constraintTypes = null, string? bindingSourceId = null, string? descriptorName = null)
{
return new ParameterApiDescriptionModel
{

@ -9,13 +9,13 @@ namespace Volo.Abp.Http.Modeling;
[Serializable]
public class PropertyApiDescriptionModel
{
public string Name { get; set; }
public string Name { get; set; } = default!;
public string JsonName { get; set; }
public string? JsonName { get; set; }
public string Type { get; set; }
public string Type { get; set; } = default!;
public string TypeSimple { get; set; }
public string TypeSimple { get; set; } = default!;
public bool IsRequired { get; set; }
@ -23,11 +23,11 @@ public class PropertyApiDescriptionModel
public int? MaxLength { get; set; }
public string Minimum { get; set; }
public string? Minimum { get; set; }
public string Maximum { get; set; }
public string? Maximum { get; set; }
public string Regex { get; set; }
public string? Regex { get; set; }
public static PropertyApiDescriptionModel Create(PropertyInfo propertyInfo)
{

@ -7,9 +7,9 @@ namespace Volo.Abp.Http.Modeling;
[Serializable]
public class ReturnValueApiDescriptionModel
{
public string Type { get; set; }
public string Type { get; set; } = default!;
public string TypeSimple { get; set; }
public string TypeSimple { get; set; } = default!;
public ReturnValueApiDescriptionModel()
{

@ -7,17 +7,17 @@ namespace Volo.Abp.Http.Modeling;
[Serializable]
public class TypeApiDescriptionModel
{
public string BaseType { get; set; }
public string? BaseType { get; set; }
public bool IsEnum { get; set; }
public string[] EnumNames { get; set; }
public string[]? EnumNames { get; set; }
public object[] EnumValues { get; set; }
public object[]? EnumValues { get; set; }
public string[] GenericArguments { get; set; }
public string[]? GenericArguments { get; set; }
public PropertyApiDescriptionModel[] Properties { get; set; }
public PropertyApiDescriptionModel[]? Properties { get; set; }
public TypeApiDescriptionModel()
{

@ -5,7 +5,7 @@ namespace Volo.Abp.Http.ProxyScripting.Configuration;
public static class AbpApiProxyScriptingConfiguration
{
public static Func<PropertyInfo, string> PropertyNameGenerator { get; set; }
public static Func<PropertyInfo, string?> PropertyNameGenerator { get; set; }
static AbpApiProxyScriptingConfiguration()
{

@ -135,16 +135,16 @@ public class JQueryProxyScriptGenerator : IProxyScriptGenerator, ITransientDepen
private static string FindBestApiVersion(ActionApiDescriptionModel action)
{
//var configuredVersion = GetConfiguredApiVersion(); //TODO: Implement
string configuredVersion = null;
string? configuredVersion = null;
if (action.SupportedVersions.IsNullOrEmpty())
{
return configuredVersion ?? "1.0";
}
if (action.SupportedVersions.Contains(configuredVersion))
if (action.SupportedVersions!.Contains(configuredVersion!))
{
return configuredVersion;
return configuredVersion!;
}
return action.SupportedVersions.Last(); //TODO: Ensure to get the latest version!

@ -25,7 +25,7 @@ internal static class ProxyScriptingHelper
}
}
public static string GenerateHeaders(ActionApiDescriptionModel action, int indent = 0)
public static string? GenerateHeaders(ActionApiDescriptionModel action, int indent = 0)
{
var parameters = action
.Parameters
@ -40,7 +40,7 @@ internal static class ProxyScriptingHelper
return ProxyScriptingJsFuncHelper.CreateJsObjectLiteral(parameters, indent);
}
public static string GenerateBody(ActionApiDescriptionModel action)
public static string? GenerateBody(ActionApiDescriptionModel action)
{
var parameters = action
.Parameters
@ -62,7 +62,7 @@ internal static class ProxyScriptingHelper
return ProxyScriptingJsFuncHelper.GetParamNameInJsFunc(parameters[0]);
}
public static string GenerateFormPostData(ActionApiDescriptionModel action, int indent = 0)
public static string? GenerateFormPostData(ActionApiDescriptionModel action, int indent = 0)
{
var parameters = action
.Parameters

@ -8,11 +8,11 @@ public class ProxyScriptingModel
public bool UseCache { get; set; }
public string[] Modules { get; set; }
public string[]? Modules { get; set; }
public string[] Controllers { get; set; }
public string[]? Controllers { get; set; }
public string[] Actions { get; set; }
public string[]? Actions { get; set; }
public IDictionary<string, string> Properties { get; set; }

Loading…
Cancel
Save