public void Apply(Schema model, ModelFilterContext context)
        {
            XPathNavigator navigator;

            lock (this._xmlDoc)
                navigator = this._xmlDoc.CreateNavigator();
            string         commentIdForType = XmlCommentsIdHelper.GetCommentIdForType(context.SystemType);
            XPathNavigator xpathNavigator   = navigator.SelectSingleNode(string.Format("/doc/members/member[@name='{0}']", (object)commentIdForType));

            if (xpathNavigator != null)
            {
                XPathNavigator node = xpathNavigator.SelectSingleNode("summary");
                if (node != null)
                {
                    model.description = node.ExtractContent();
                }
            }
            if (model.properties == null)
            {
                return;
            }
            foreach (KeyValuePair <string, Schema> property1 in (IEnumerable <KeyValuePair <string, Schema> >)model.properties)
            {
                JsonProperty property2 = ((KeyedCollection <string, JsonProperty>)context.JsonObjectContract.get_Properties())[property1.Key];
                if (property2 != null)
                {
                    ApplyXmlTypeComments.ApplyPropertyComments(navigator, property1.Value, property2.PropertyInfo());
                }
            }
        }
        private void ApplyPropertyComments(Schema model, ModelFilterContext context)
        {
            foreach (var entry in model.properties)
            {
                var jsonProperty = context.JsonObjectContract.Properties[entry.Key];
                if (jsonProperty == null)
                {
                    continue;
                }

                var propertyInfo = jsonProperty.PropertyInfo();
                if (propertyInfo != null)
                {
                    var propCommentId = propertyInfo.GetCommentId();
                    ApplyComments(navigator, entry.Value, propCommentId);
                }
                else
                {
                    var fieldInfo = jsonProperty.FieldInfo();
                    if (fieldInfo != null)
                    {
                        var propCommentId = fieldInfo.GetCommentId();
                        ApplyComments(navigator, entry.Value, propCommentId);
                    }
                }
            }
        }
示例#3
0
 public void Apply(Schema model, ModelFilterContext context)
 {
     model.Default = new
     {
         Id = "myCartId"
     };
 }
示例#4
0
        public void Apply(Schema model, ModelFilterContext context)
        {
            var typeXPath = string.Format(TypeExpression, context.SystemType.XmlLookupName());
            var typeNode  = _navigator.SelectSingleNode(typeXPath);

            if (typeNode != null)
            {
                var summaryNode = typeNode.SelectSingleNode(SummaryExpression);
                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 Apply(Schema model, ModelFilterContext context)
        {
            var commentId = context.SystemType.GetCommentId();
            var typeNode  = navigator.SelectSingleNode(string.Format(MemberXPath, commentId));

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

                var exampleNode = typeNode.SelectSingleNode(ExampleTag);
                if (exampleNode != null)
                {
                    model.example = exampleNode.ExtractContent();
                }
            }

            if (model.properties != null)
            {
                ApplyPropertyComments(model, context);
            }
        }
        public void Apply(Schema model, ModelFilterContext context)
        {
            var typeNode = _navigator.SelectSingleNode(
                String.Format(TypeExpression, context.SystemType.XmlCommentsId()));

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

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

                var memberInfo = jsonProperty.PropertyInfo();
                if (memberInfo != null)
                {
                    ApplyPropertyComments(entry.Value, memberInfo);
                }
            }
        }
        public void Apply(Schema model, ModelFilterContext context)
        {
            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)
                {
                    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());
            }
        }
示例#8
0
        public void Apply(Schema model, ModelFilterContext context)
        {
            _logger.LogInformation("Applying an awesome IModelFilter that leverages Dependency Injection");

            model.Default = new
            {
                Id = "myCartId"
            };
        }
        public void Apply(Schema model, ModelFilterContext context)
        {
            var typeInfo   = context.SystemType.GetTypeInfo();
            var attributes = typeInfo.GetCustomAttributes(false).OfType <SwaggerModelFilterAttribute>();

            foreach (var attribute in attributes)
            {
                var filter = (IModelFilter)Activator.CreateInstance(attribute.FilterType);
                filter.Apply(model, context);
            }
        }
示例#10
0
        public void Apply(Schema model, ModelFilterContext context)
        {
            var typeInfo   = context.SystemType.GetTypeInfo();
            var attributes = typeInfo.GetCustomAttributes(false).OfType <SwaggerModelFilterAttribute>();

            foreach (var attr in attributes)
            {
                var filter = (IModelFilter)ActivatorUtilities.CreateInstance(_serviceProvider, attr.Type, attr.Arguments);
                filter.Apply(model, context);
            }
        }
        public void Apply(Schema model, ModelFilterContext context)
        {
            var typeInfo = context.SystemType.GetTypeInfo();
            var attributes = typeInfo.GetCustomAttributes(false).OfType<SwaggerModelFilterAttribute>();

            foreach (var attribute in attributes)
            {
                var filter = (IModelFilter)Activator.CreateInstance(attribute.FilterType);
                filter.Apply(model, context);
            }
        }
        public void Apply(Schema model, ModelFilterContext context)
        {
            model.description = GetDocumentation(context.SystemType);

            //Properties
            model.properties.Clear();
            foreach (var property in context.SystemType.GetProperties())
            {
                model.properties[property.Name] = new Schema()
                {
                    description = GetDocumentation(property)
                };
            }
            ;
        }
示例#13
0
        public void Apply(Schema model, ModelFilterContext context)
        {
            var typeXPath = string.Format(TypeExpression, context.SystemType.XmlLookupName());
            var typeNode = _navigator.SelectSingleNode(typeXPath);

            if (typeNode != null)
            {
                var summaryNode = typeNode.SelectSingleNode(SummaryExpression);
                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 Apply(Schema model, ModelFilterContext context)
        {
            XPathNavigator navigator;

            lock (_xmlDoc)
            {
                navigator = _xmlDoc.CreateNavigator();
            }

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

                var exampleNode = typeNode.SelectSingleNode(ExampleTag);
                if (exampleNode != null)
                {
                    model.example = exampleNode.ExtractContent();
                }
            }

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

                    ApplyPropertyComments(navigator, entry.Value, jsonProperty.PropertyInfo());
                }
            }
        }
        public void SchemaRegistry_Null()
        {
            var x = new ModelFilterContext(null, null, null);

            Assert.IsNull(x.SchemaRegistry);
        }
 public void Apply(Schema model, ModelFilterContext context)
 {
     model.Extensions.Add("X-property1", "value");
 }
示例#17
0
 public void Apply(Schema model, ModelFilterContext context)
 {
 }