Пример #1
0
 public EndpointContext(ApiDocGenerator gen, Type tController, ApiControllerDocAttribute cattr, ApiEndpointDocAttribute eattr, MethodInfo method)
 {
     Generator            = gen;
     TController          = tController;
     ApiControllerDocAttr = cattr;
     ApiEndpointDocAttr   = eattr;
     Method = method;
 }
        private (Lazy <ConfigSectionNode> request, Lazy <ConfigSectionNode> response) writeCommon(
            string defTitle,
            string defDescription,
            MemberInfo info,
            ApiDocGenerator gen,
            ApiDocAttribute attr,
            ConfigSectionNode data)
        {
            MetadataUtils.AddMetadataTokenIdAttribute(data, info);

            var title = attr.Title.Default(defTitle);

            if (title.IsNotNullOrWhiteSpace())
            {
                data.AddAttributeNode("title", title);
            }

            var descr = attr.Description.Default(defDescription);

            if (descr.IsNotNullOrWhiteSpace())
            {
                data.AddAttributeNode("description", descr);
            }

            var drequest  = new Lazy <ConfigSectionNode>(() => data.AddChildNode("request"));
            var dresponse = new Lazy <ConfigSectionNode>(() => data.AddChildNode("response"));

            writeCollection(attr.RequestHeaders, "header", drequest, ':');
            writeCollection(attr.RequestQueryParameters, "param", drequest, '=');
            writeCollection(attr.ResponseHeaders, "header", dresponse, ':');

            if (attr.Connection.IsNotNullOrWhiteSpace())
            {
                data.AddAttributeNode("connection", attr.Connection);
            }

            if (attr.RequestBody.IsNotNullOrWhiteSpace())
            {
                drequest.Value.AddAttributeNode("body", attr.RequestBody);
            }

            if (attr.ResponseContent.IsNotNullOrWhiteSpace())
            {
                dresponse.Value.AddAttributeNode("content", attr.ResponseContent);
            }

            writeTypeCollection(attr.TypeSchemas, TYPE_REF, data, gen);

            return(drequest, dresponse);
        }
Пример #3
0
 public ControllerContext(ApiDocGenerator gen, ApiControllerDocAttribute attr)
 {
     Generator  = gen;
     ApiDocAttr = attr;
 }
 private void writeInstanceCollection(object[] items, string iname, ConfigSectionNode data, ApiDocGenerator gen)
 {
     if (items != null && items.Length > 0)
     {
         foreach (var item in items.Where(i => i != null))
         {
             var titem = item.GetType();
             var id    = gen.AddTypeToDescribe(titem, item);
             var node  = data.Children.FirstOrDefault(c => c.IsSameName(iname) && c.AttrByName("id").Value.EqualsIgnoreCase(id));
             if (node != null)
             {
                 continue;    //already exists
             }
             data.AddAttributeNode(iname, id);
         }
     }
 }