private void ApplyPropertiesXmlToPropertyParameters(
            IList <IParameter> parameters,
            ServiceEntry serviceEntry)
        {
            if (parameters == null)
            {
                return;
            }

            foreach (var parameter in parameters)
            {
                var methodInfo = serviceEntry.Type.GetTypeInfo().DeclaredMethods
                                 .Where(p => p.Name == serviceEntry.MethodName).FirstOrDefault();
                var propertyParam = methodInfo.GetParameters()
                                    .FirstOrDefault(p => parameter.Name.Equals(p.Name, StringComparison.OrdinalIgnoreCase));
                if (propertyParam == null)
                {
                    continue;
                }
                var memberInfo = propertyParam.Member;
                if (memberInfo == null)
                {
                    continue;
                }

                var memberName = XmlCommentsMemberNameHelper.GetMemberNameForMember(memberInfo);
                var memberNode = _xmlNavigator.SelectSingleNode(string.Format(MemberXPath, memberName));
                if (memberNode == null)
                {
                    continue;
                }

                var summaryNode = memberNode.SelectSingleNode(SummaryXPath);
                if (summaryNode != null)
                {
                    parameter.Description = XmlCommentsTextHelper.Humanize(summaryNode.InnerXml);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Applies the specified schema.
        /// </summary>
        /// <param name="schema">The schema.</param>
        /// <param name="context">The context.</param>
        public void Apply(Schema schema, SchemaFilterContext context)
        {
            var jsonObjectContract = context.JsonContract as JsonObjectContract;

            if (jsonObjectContract == null)
            {
                return;
            }

            var memberName = XmlCommentsMemberNameHelper.GetMemberNameForType(context.SystemType);
            var typeNode   = _xmlNavigator.SelectSingleNode(string.Format(MemberXPath, memberName));

            if (typeNode != null)
            {
                var summaryNode = typeNode.SelectSingleNode(SummaryTag);
                if (summaryNode != null)
                {
                    schema.Description = XmlCommentsTextHelper.Humanize(summaryNode.InnerXml);
                }
            }

            if (schema.Properties == null)
            {
                return;
            }
            foreach (var entry in schema.Properties)
            {
                var jsonProperty = jsonObjectContract.Properties[entry.Key];
                if (jsonProperty == null)
                {
                    continue;
                }

                if (jsonProperty.TryGetMemberInfo(out var memberInfo))
                {
                    ApplyPropertyComments(entry.Value, memberInfo);
                }
            }
        }
Exemplo n.º 3
0
        private void ApplyPropertyComments(Schema propertySchema, MemberInfo memberInfo)
        {
            var memberName = XmlCommentsMemberNameHelper.GetMemberNameForMember(memberInfo);
            var memberNode = _xmlNavigator.SelectSingleNode(string.Format(MemberXPath, memberName));

            if (memberNode == null)
            {
                return;
            }

            var summaryNode = memberNode.SelectSingleNode(SummaryTag);

            if (summaryNode != null)
            {
                propertySchema.Description = XmlCommentsTextHelper.Humanize(summaryNode.InnerXml);
            }

            var exampleNode = memberNode.SelectSingleNode(ExampleXPath);

            if (exampleNode != null)
            {
                propertySchema.Example = XmlCommentsTextHelper.Humanize(exampleNode.InnerXml);
            }
        }