private void AddParameterDescriptionsToModel(ActionApiDescriptionModel actionModel, MethodInfo method, ApiDescription apiDescription) { if (!apiDescription.ParameterDescriptions.Any()) { return; } var matchedMethodParamNames = ArrayMatcher.Match( apiDescription.ParameterDescriptions.Select(p => p.Name).ToArray(), method.GetParameters().Select(GetMethodParamName).ToArray() ); for (var i = 0; i < apiDescription.ParameterDescriptions.Count; i++) { var parameterDescription = apiDescription.ParameterDescriptions[i]; var matchedMethodParamName = matchedMethodParamNames.Length > i ? matchedMethodParamNames[i] : parameterDescription.Name; actionModel.AddParameter(new ParameterApiDescriptionModel( parameterDescription.Name, matchedMethodParamName, parameterDescription.Type, parameterDescription.RouteInfo?.IsOptional ?? false, parameterDescription.RouteInfo?.DefaultValue, parameterDescription.RouteInfo?.Constraints?.Select(c => c.GetType().Name).ToArray(), parameterDescription.Source.Id ) ); } }
private void AddParameterDescriptionsToModel(ActionApiDescriptionModel actionModel, MethodInfo method, ApiDescription apiDescription) { if (!apiDescription.ParameterDescriptions.Any()) { return; } var paramInfos = method.GetParameters(); foreach (var p in paramInfos) { var name = GetMethodParamName(p); actionModel.AddParameter(new ParameterApiDescriptionModel( name, name, p.ParameterType, p.IsOptional, p.DefaultValue, null, null ) ); } /* * //var matchedMethodParamNames = ArrayMatcher.Match( * // apiDescription.ParameterDescriptions.Select(p => p.Name).ToArray(), * // method.GetParameters().Select(GetMethodParamName).ToArray() * //); * * for (var i = 0; i < apiDescription.ParameterDescriptions.Count; i++) * { * var parameterDescription = apiDescription.ParameterDescriptions[i]; * //var matchedMethodParamName = matchedMethodParamNames.Length > i * // ? matchedMethodParamNames[i] * // : parameterDescription.Name; * * actionModel.AddParameter(new ParameterApiDescriptionModel( * parameterDescription.Name, * "",//matchedMethodParamName, * parameterDescription.Type, * parameterDescription.RouteInfo?.IsOptional ?? false, * parameterDescription.RouteInfo?.DefaultValue, * parameterDescription.RouteInfo?.Constraints?.Select(c => c.GetType().Name).ToArray(), * parameterDescription.Source.Id * ) * ); * } */ }
private void AddParameterDescriptionsToModel(ActionApiDescriptionModel actionModel, MethodInfo method, ApiDescription apiDescription) { if (!apiDescription.ParameterDescriptions.Any()) { return; } var parameterDescriptionNames = apiDescription .ParameterDescriptions .Select(p => p.Name) .ToArray(); var methodParameterNames = method .GetParameters() .Where(IsNotFromServicesParameter) .Select(GetMethodParamName) .ToArray(); var matchedMethodParamNames = ArrayMatcher.Match( parameterDescriptionNames, methodParameterNames ); for (var i = 0; i < apiDescription.ParameterDescriptions.Count; i++) { var parameterDescription = apiDescription.ParameterDescriptions[i]; var matchedMethodParamName = matchedMethodParamNames.Length > i ? matchedMethodParamNames[i] : parameterDescription.Name; actionModel.AddParameter(ParameterApiDescriptionModel.Create( parameterDescription.Name, _options.ApiParameterNameGenerator?.Invoke(parameterDescription), matchedMethodParamName, parameterDescription.Type, parameterDescription.RouteInfo?.IsOptional ?? false, parameterDescription.RouteInfo?.DefaultValue, parameterDescription.RouteInfo?.Constraints?.Select(c => c.GetType().Name).ToArray(), parameterDescription.Source.Id, parameterDescription.ModelMetadata?.ContainerType != null ? parameterDescription.ParameterDescriptor?.Name ?? string.Empty : string.Empty ) ); } }