public void GetMemberNameForType_ReturnsCorrectXmlCommentsMemberName_ForGivenType(
            Type type,
            string expectedMemberName
            )
        {
            var memberName = XmlCommentsMemberNameHelper.GetMemberNameForType(type);

            _output.WriteLine(expectedMemberName);
            _output.WriteLine(memberName);
            Assert.Equal(expectedMemberName, memberName);
        }
        public void GetMemberNameForMethod_ReturnsCorrectXmlCommentsMemberName_ForGivenMethodInfo(
            Type declaringType,
            string name,
            string expectedMemberName)
        {
            var methodInfo = declaringType.GetMethod(name);

            var memberName = XmlCommentsMemberNameHelper.GetMemberNameForMethod(methodInfo);

            _output.WriteLine(expectedMemberName);
            _output.WriteLine(memberName);
            Assert.Equal(expectedMemberName, memberName);
        }
        public void GetMemberNameForProperty_ReturnsCorrectXmlCommentMemberName_ForGivenMemberInfo(
            Type declaringType,
            string fieldOrPropertyName,
            string expectedMemberName
            )
        {
            var memberInfo = declaringType.GetMember(fieldOrPropertyName)[0];

            var memberName = XmlCommentsMemberNameHelper.GetMemberNameForMember(memberInfo);

            _output.WriteLine(expectedMemberName);
            _output.WriteLine(memberName);
            Assert.Equal(expectedMemberName, memberName);
        }
예제 #4
0
        public void Apply(Operation operation, OperationFilterContext context)
        {
            if (context.MethodInfo == (MethodInfo)null)
            {
                return;
            }
            MethodInfo method = context.MethodInfo.DeclaringType.IsConstructedGenericType ? this.GetGenericTypeMethodOrNullFor(context.MethodInfo) : context.MethodInfo;

            if (method == (MethodInfo)null)
            {
                return;
            }
            XPathNavigator methodNode = this._xmlNavigator.SelectSingleNode(string.Format("/doc/members/member[@name='{0}']", (object)XmlCommentsMemberNameHelper.GetMemberNameForMethod(method)));

            if (methodNode != null)
            {
                this.ApplyMethodXmlToOperation(operation, methodNode, context.ApiDescription);
                this.ApplyParamsXmlToActionParameters(operation.Parameters, methodNode, context.ApiDescription);
                this.ApplyResponsesXmlToResponses(operation.Responses, methodNode.Select("response"));
            }
            this.ApplyPropertiesXmlToPropertyParameters(operation.Parameters, context.ApiDescription);
        }
예제 #5
0
 private void ApplyPropertiesXmlToPropertyParameters(IList <IParameter> parameters, ApiDescription apiDescription)
 {
     if (parameters == null)
     {
         return;
     }
     foreach (IParameter parameter1 in (IEnumerable <IParameter>)parameters)
     {
         IParameter parameter = parameter1;
         ApiParameterDescription parameterDescription = apiDescription.ParameterDescriptions.Where <ApiParameterDescription>((Func <ApiParameterDescription, bool>)(p =>
         {
             if (p.ModelMetadata?.ContainerType != (Type)null)
             {
                 return(p.ModelMetadata?.PropertyName != null);
             }
             return(false);
         })).FirstOrDefault <ApiParameterDescription>((Func <ApiParameterDescription, bool>)(p => parameter.Name.Equals(p.Name, StringComparison.OrdinalIgnoreCase)));
         if (parameterDescription != null)
         {
             ModelMetadata modelMetadata = parameterDescription.ModelMetadata;
             MemberInfo    memberInfo    = ((IEnumerable <MemberInfo>)modelMetadata.ContainerType.GetMember(modelMetadata.PropertyName)).FirstOrDefault <MemberInfo>();
             if (!(memberInfo == (MemberInfo)null))
             {
                 XPathNavigator xpathNavigator1 = this._xmlNavigator.SelectSingleNode(string.Format("/doc/members/member[@name='{0}']", (object)XmlCommentsMemberNameHelper.GetMemberNameForMember(memberInfo)));
                 if (xpathNavigator1 != null)
                 {
                     XPathNavigator xpathNavigator2 = xpathNavigator1.SelectSingleNode("summary");
                     if (xpathNavigator2 != null)
                     {
                         parameter.Description = XmlCommentsTextHelper.Humanize(xpathNavigator2.InnerXml);
                     }
                 }
             }
         }
     }
 }
예제 #6
0
 public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context)
 {
     foreach (var keyValuePair in context.ApiDescriptions
              .Select(apiDesc => apiDesc.ActionDescriptor as ControllerActionDescriptor)
              .SkipWhile(actionDesc => actionDesc == null)
              .GroupBy(actionDesc => {
         // ReSharper disable once AssignNullToNotNullAttribute
         var attr = actionDesc
                    .MethodInfo
                    .DeclaringType
                    .GetCustomAttribute <DisplayNameAttribute>();
         return(attr?.DisplayName ?? actionDesc.ControllerName);
     })
              .ToDictionary(grp => grp.Key, grp => grp.Last().ControllerTypeInfo.AsType()))
     {
         var xpathNavigator1 = _xmlNavigator.SelectSingleNode($"/doc/members/member[@name='{XmlCommentsMemberNameHelper.GetMemberNameForType(keyValuePair.Value)}']");
         var xpathNavigator2 = xpathNavigator1?.SelectSingleNode("summary");
         if (xpathNavigator2 != null)
         {
             if (swaggerDoc.Tags == null)
             {
                 swaggerDoc.Tags = new List <Tag>();
             }
             swaggerDoc.Tags.Add(new Tag()
             {
                 Name        = keyValuePair.Key,
                 Description = XmlCommentsTextHelper.Humanize(xpathNavigator2.InnerXml)
             });
         }
     }
 }