Ejemplo n.º 1
0
        public void Humanize_TrimsWhiteSpaceFromStartAndEnd()
        {
            var input = @"
 A line of text
            ";

            var output = XmlCommentsTextHelper.Humanize(input);

            Assert.Equal("A line of text", output);
        }
Ejemplo n.º 2
0
        private static void ApplyResponseComments(Operation operation, XPathNavigator methodNode)
        {
            var responseNodes = methodNode.Select(ResponsesXPath);

            while (responseNodes.MoveNext())
            {
                var responseNode = responseNodes.Current;
                var code         = responseNode.GetAttribute("code", "");

                var response = operation.Responses.ContainsKey(code)
                    ? operation.Responses[code]
                    : operation.Responses[code] = new Response();

                response.Description = XmlCommentsTextHelper.Humanize(responseNode.InnerXml);
            }
        }
Ejemplo n.º 3
0
        private void ApplyPropertyComments(Schema propertySchema, PropertyInfo propertyInfo)
        {
            var commentId    = XmlCommentsIdHelper.GetCommentIdForProperty(propertyInfo);
            var propertyNode = _xmlNavigator.SelectSingleNode(string.Format(MemberXPath, commentId));

            if (propertyNode == null)
            {
                return;
            }

            var summaryNode = propertyNode.SelectSingleNode(SummaryTag);

            if (summaryNode != null)
            {
                propertySchema.Description = XmlCommentsTextHelper.Humanize(summaryNode.InnerXml);
            }
        }
Ejemplo n.º 4
0
        public void Humanize_TrimsCommonSpaceTabIndentations()
        {
            // Common indentation seen in visual studio: {space}{tab}
            var input = @"
                ## Heading 1

                A line of text
            "            ;

            var output = XmlCommentsTextHelper.Humanize(input);

            Assert.Equal(
                @"## Heading 1

A line of text",
                output
                );
        }
Ejemplo n.º 5
0
        public void Humanize_DoesNotTrimInconsistentIndentations()
        {
            var input = @"
                Space Indentation Line 1
                Space Indentation Line 2
                Misplaced Tab Indentation
                Space Indentation Line 4
            ";

            var output = XmlCommentsTextHelper.Humanize(input);

            Assert.Equal(
                @"    Space Indentation Line 1
    Space Indentation Line 2
	Misplaced Tab Indentation
    Space Indentation Line 4",
                output);
        }
Ejemplo n.º 6
0
        private static void ApplyParamComments(Operation operation, XPathNavigator methodNode)
        {
            if (operation.Parameters == null)
            {
                return;
            }

            var paramNodes = methodNode.Select(ParameterTag);

            while (paramNodes.MoveNext())
            {
                var paramNode = paramNodes.Current;
                var parameter = operation.Parameters
                                .SingleOrDefault(param => param.Name == paramNode.GetAttribute("name", ""));
                if (parameter != null)
                {
                    parameter.Description = XmlCommentsTextHelper.Humanize(paramNode.InnerXml);
                }
            }
        }
Ejemplo n.º 7
0
        public void Apply(Schema schema, SchemaFilterContext context)
        {
            var jsonObjectContract = context.JsonContract as JsonObjectContract;

            if (jsonObjectContract == null)
            {
                return;
            }

            var commentId = XmlCommentsIdHelper.GetCommentIdForType(context.SystemType);
            var typeNode  = _xmlNavigator.SelectSingleNode(string.Format(MemberXPath, commentId));

            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;
                }

                var propertyInfo = jsonProperty.PropertyInfo();
                if (propertyInfo != null)
                {
                    ApplyPropertyComments(entry.Value, propertyInfo);
                }
            }
        }
Ejemplo n.º 8
0
        public void Humanize_TrimsCommonSpaceIndentations()
        {
            var input = @"
                ## Heading 1

                  * list item 1

                ## Heading 2

                    POST /api/test

                    {
                      ""prop1"": {
                        ""name"": ""value""
                      }
                    }
            ";

            var output = XmlCommentsTextHelper.Humanize(input);

            Assert.Equal(
                @"## Heading 1

  * list item 1

## Heading 2

	POST /api/test

	{
	  ""prop1"": {
	    ""name"": ""value""
	  }
	}"    ,
                output
                );
        }