Exemplo n.º 1
0
        private void ApplyConstraintsXmlToActionParameters(IList <IParameter> parameters, ApiDescription apiDescription)
        {
            var nonBodyParameters = parameters.OfType <NonBodyParameter>();

            foreach (var parameter in nonBodyParameters)
            {                // Check for a corresponding action parameter?
                var actionParameter = apiDescription.ParameterDescriptions.FirstOrDefault(p =>
                                                                                          parameter.Name.Equals(p.Name, StringComparison.OrdinalIgnoreCase));
                if (actionParameter == null)
                {
                    continue;
                }

                if (!actionParameter.RouteInfo.Constraints.Any())
                {
                    continue;
                }

                var constraintType        = actionParameter.RouteInfo.Constraints.FirstOrDefault().GetType();
                var commentIdForType      = XmlCommentsIdHelper.GetCommentIdForType(constraintType);
                var constraintSummaryNode = _xmlNavigator
                                            .SelectSingleNode(string.Format(MemberXPath, commentIdForType))
                                            ?.SelectSingleNode(SummaryXPath);
                if (constraintSummaryNode != null)
                {
                    parameter.Description = XmlCommentsTextHelper.Humanize(constraintSummaryNode.InnerXml);
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// old ImodelFilter way
        /// </summary>
        /// <param name="model"></param>
        /// <param name="context"></param>
        private void Apply(Schema model, ModelFilterContext context)
        {
            var commentId = XmlCommentsIdHelper.GetCommentIdForType(context.SystemType);
            var typeNode  = _navigator.SelectSingleNode(string.Format(MemberXPath, commentId));

            if (typeNode != null)
            {
                var summaryNode = typeNode.SelectSingleNode(SummaryTag);
                if (summaryNode != null)
                {
                    model.description = summaryNode.ExtractContent();
                }
            }

            foreach (var entry in model.properties)
            {
                var jsonProperty = context.JsonObjectContract.Properties[entry.Key];
                if (jsonProperty == null)
                {
                    continue;
                }

                ApplyPropertyComments(entry.Value, jsonProperty.PropertyInfo());
            }
        }
Exemplo n.º 3
0
        public void GetCommentIdForType_ReturnsCorrectXmlCommentId_ForGivenType(
            Type type,
            string expectedCommentId
            )
        {
            var commentId = XmlCommentsIdHelper.GetCommentIdForType(type);

            Assert.Equal(expectedCommentId, commentId);
        }
Exemplo n.º 4
0
        /// <summary>
        /// new way
        /// </summary>
        /// <param name="model"></param>
        /// <param name="schemaRegistry"></param>
        /// <param name="type"></param>
        public void Apply(Schema model, SchemaRegistry schemaRegistry, Type type)
        {
            var commentId = XmlCommentsIdHelper.GetCommentIdForType(type);
            var typeNode  = _navigator.SelectSingleNode(string.Format(MemberXPath, commentId));

            if (typeNode != null)
            {
                var summaryNode = typeNode.SelectSingleNode(SummaryTag);
                if (summaryNode != null)
                {
                    model.description = summaryNode.ExtractContent();
                }
            }
            //var _contractResolver = schemaRegistry.jsonSerializerSettings.ContractResolver ?? new DefaultContractResolver();
            foreach (var entry in model.properties)
            {
                continue;//TODO figure out how to get 'context' from model
                //var jsonProperty = context.JsonObjectContract.Properties[entry.Key];
                //if (jsonProperty == null) continue;

                //ApplyPropertyComments(entry.Value, jsonProperty.PropertyInfo());
            }
        }