Ejemplo n.º 1
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);
            }
        }
        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 propertyInfo = metadata.ContainerType.GetTypeInfo().GetProperty(metadata.PropertyName);
                if (propertyInfo == null)
                {
                    continue;
                }

                var commentId    = XmlCommentsIdHelper.GetCommentIdForProperty(propertyInfo);
                var propertyNode = _xmlNavigator.SelectSingleNode(string.Format(MemberXPath, commentId));
                if (propertyNode == null)
                {
                    continue;
                }

                var summaryNode = propertyNode.SelectSingleNode(SummaryXPath);
                if (summaryNode != null)
                {
                    parameter.Description = XmlCommentsTextHelper.Humanize(summaryNode.InnerXml);
                }
            }
        }
Ejemplo n.º 3
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);
                }
            }
        }
        public void Apply(Operation operation, OperationFilterContext context)
        {
            var controllerActionDescriptor = context.ApiDescription.ActionDescriptor as ControllerActionDescriptor;

            if (controllerActionDescriptor == null)
            {
                return;
            }

            var commentId  = XmlCommentsIdHelper.GetCommentIdForMethod(controllerActionDescriptor.MethodInfo);
            var methodNode = _xmlNavigator.SelectSingleNode(string.Format(MemberXPath, commentId));

            if (methodNode != null)
            {
                ApplyMethodXmlToOperation(operation, methodNode);
                ApplyParamsXmlToActionParameters(operation.Parameters, methodNode, context.ApiDescription);
                ApplyResponsesXmlToResponses(operation.Responses, methodNode.Select(ResponsesXPath));
            }

            // Special handling for parameters that are bound to model properties
            ApplyPropertiesXmlToPropertyParameters(operation.Parameters, context.ApiDescription);
        }