private void ApplyResponsesXmlToResponses(IDictionary <string, Response> responses,
                                                  XPathNodeIterator responseNodes)
        {
            while (responseNodes.MoveNext())
            {
                var code     = responseNodes.Current.GetAttribute("code", "");
                var response = responses.ContainsKey(code)
                    ? responses[code]
                    : responses[code] = new Response();

                response.Description = XmlCommentsTextHelper.Humanize(responseNodes.Current.InnerXml);
            }
        }
        private void ApplyMethodXmlToOperation(Operation operation, XPathNavigator methodNode)
        {
            var summaryNode = methodNode.SelectSingleNode(SummaryXPath);

            if (summaryNode != null)
            {
                operation.Summary = XmlCommentsTextHelper.Humanize(summaryNode.InnerXml);
            }

            var remarksNode = methodNode.SelectSingleNode(RemarksXPath);

            if (remarksNode != null)
            {
                operation.Description = XmlCommentsTextHelper.Humanize(remarksNode.InnerXml);
            }
        }
        private void ApplyPropertiesXmlToPropertyParameters(
            IList <IParameter> parameters,
            ApiDescription apiDescription)
        {
            if (parameters == null)
            {
                return;
            }

            foreach (var parameter in parameters)
            {
                // Check for a corresponding  API parameter (from ApiExplorer) that's property-bound?
                var propertyParam = apiDescription.ParameterDescriptions
                                    .Where(p => p.ModelMetadata?.ContainerType != null && p.ModelMetadata?.PropertyName != null)
                                    .FirstOrDefault(p => parameter.Name.Equals(p.Name, StringComparison.OrdinalIgnoreCase));
                if (propertyParam == null)
                {
                    continue;
                }

                var metadata   = propertyParam.ModelMetadata;
                var memberInfo = metadata.ContainerType.GetMember(metadata.PropertyName).FirstOrDefault();
                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);
                }
            }
        }
        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);
                }
            }
        }
예제 #5
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);
                }
            }
        }
예제 #6
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);
            }
        }