Exemple #1
0
        public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context)
        {
            // Collect (unique) controller names and types in a dictionary
            var controllerNamesAndTypes = context.ApiDescriptions
                                          .Select(apiDesc => apiDesc.ActionDescriptor as ControllerActionDescriptor)
                                          .SkipWhile(actionDesc => actionDesc == null)
                                          .GroupBy(actionDesc => actionDesc.ControllerName)
                                          .ToDictionary(grp => grp.Key, grp => grp.Last().ControllerTypeInfo.AsType());

            foreach (var nameAndType in controllerNamesAndTypes)
            {
                var memberName = XmlCommentsMemberNameHelper.GetMemberNameForType(nameAndType.Value);
                var typeNode   = _xmlNavigator.SelectSingleNode(string.Format(MemberXPath, memberName));

                if (typeNode != null)
                {
                    var summaryNode = typeNode.SelectSingleNode(SummaryTag);
                    if (summaryNode != null)
                    {
                        if (swaggerDoc.Tags == null)
                        {
                            swaggerDoc.Tags = new List <Tag>();
                        }

                        swaggerDoc.Tags.Add(new Tag
                        {
                            Name        = nameAndType.Key,
                            Description = XmlCommentsTextHelper.Humanize(summaryNode.InnerXml)
                        });
                    }
                }
            }
        }
Exemple #2
0
        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 MemberInfo memberInfo))
                {
                    ApplyPropertyComments(entry.Value, memberInfo);
                }
            }
        }