<commit_before>﻿using System;
using System.Xml.XPath;
using Swashbuckle.Swagger;
using System.Collections.Generic;

namespace Swashbuckle.Swagger.Filters
{
    public class ApplyXmlTypeComments : ISchemaFilter
    {
        private const string TypeExpression = "/doc/members/member[@name='T:{0}']";
        private const string SummaryExpression = "summary";
        private const string PropertyExpression = "/doc/members/member[@name='P:{0}.{1}']";

        private readonly XPathNavigator _navigator;

        public ApplyXmlTypeComments(string xmlCommentsPath)
        {
            _navigator = new XPathDocument(xmlCommentsPath).CreateNavigator();
        }

        public void Apply(Schema schema, SchemaRegistry schemaRegistry, Type type)
        {
            var typeNode = _navigator.SelectSingleNode(String.Format(TypeExpression, type.FullName));
            if (typeNode == null) return;

            var summaryNode = typeNode.SelectSingleNode(SummaryExpression);
            if (summaryNode != null)
                schema.description = summaryNode.Value.Trim();

            List<Type> typeList = new List<Type>();
            typeList.Add(type);
            while (typeList[typeList.Count - 1].BaseType != null)
            {
                typeList.Add(typeList[typeList.Count - 1].BaseType);
            }

            foreach (var property in schema.properties)
            {
                XPathNavigator propertyNode = null;

                foreach (Type t in typeList)
                {
                    propertyNode = _navigator.SelectSingleNode(String.Format(PropertyExpression, t.FullName, property.Key));
                    if (propertyNode != null) { break; }
                }
                if (propertyNode != null)
                    property.Value.description = propertyNode.Value.Trim();
            }
        }
    }
}<commit_msg>Changed ApplyXmlTypeComments to use the summary xml comment node to populate the description field for properties. Before it was smashing all xml node values together for the description.<commit_after>﻿using System;
using System.Xml.XPath;
using Swashbuckle.Swagger;
using System.Collections.Generic;

namespace Swashbuckle.Swagger.Filters
{
    public class ApplyXmlTypeComments : ISchemaFilter
    {
        private const string TypeExpression = "/doc/members/member[@name='T:{0}']";
        private const string SummaryExpression = "summary";
        private const string PropertyExpression = "/doc/members/member[@name='P:{0}.{1}']";

        private readonly XPathNavigator _navigator;

        public ApplyXmlTypeComments(string xmlCommentsPath)
        {
            _navigator = new XPathDocument(xmlCommentsPath).CreateNavigator();
        }

        public void Apply(Schema schema, SchemaRegistry schemaRegistry, Type type)
        {
            var typeNode = _navigator.SelectSingleNode(String.Format(TypeExpression, type.FullName));
            if (typeNode == null) return;

            var summaryNode = typeNode.SelectSingleNode(SummaryExpression);
            if (summaryNode != null)
                schema.description = summaryNode.Value.Trim();

            List<Type> typeList = new List<Type>();
            typeList.Add(type);
            while (typeList[typeList.Count - 1].BaseType != null)
            {
                typeList.Add(typeList[typeList.Count - 1].BaseType);
            }

            foreach (var property in schema.properties)
            {
                XPathNavigator propertyNode = null;

                foreach (Type t in typeList)
                {
                    propertyNode = _navigator.SelectSingleNode(String.Format(PropertyExpression, t.FullName, property.Key));
                    if (propertyNode != null) { break; }
                }
                if (propertyNode != null)
                {
                    XPathNavigator propSummaryNode = propertyNode.SelectSingleNode(SummaryExpression);
                    if (propSummaryNode != null)
                    {
                        property.Value.description = propSummaryNode.Value.Trim();
                    }
                }
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.09099639855942376, 'fraction_numerical': 0.0024009603841536613, 'mean_word_length': 2.0609845701689933, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '933029', 'n_tokens_mistral': 1056, 'n_tokens_neox': 996, 'n_words': 233}