Esempio 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);
                }
            }
        }
Esempio 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());
            }
        }
        public void GetCommentIdForType_ReturnsCorrectXmlCommentId_ForGivenType(
            Type type,
            string expectedCommentId
            )
        {
            var commentId = XmlCommentsIdHelper.GetCommentIdForType(type);

            Assert.Equal(expectedCommentId, commentId);
        }
Esempio 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());
            }
        }