private List<PostmanRequest> GetPostmanRequests(IEnumerable<SwaggerOperationDescription> apis, string collectionId, string root,SwaggerToolSettings setting)
        {
         
            List<PostmanRequest> re = new List<PostmanRequest>();
            foreach (var item in apis)
            {
                var p = new PostmanRequest
                {
                    
                    id = PostMan.GetId(),
                    name = item.Operation.Summary,
                    description = item.Operation.Summary,
                    descriptionFormat = "html",
                    headers = setting.PostmanGen.headers,
                    method = item.Method.ToString().ToUpper(),
                    pathVariables = new Dictionary<string, string>(),
                    url =root+ item.Path,
                    collectionId = collectionId,
                    tagname = item.Operation.Tags.FirstOrDefault()
                };
                var datalist = item.Operation.Parameters
                    .Where(s => s.Kind == SwaggerParameterKind.Query)
                    .Select(s =>s.Name+"={{"+s.Name+"}}")
                    .ToList();

                if (datalist.Count>0)
                {
                    p.dataMode = "params";
                    //URL Query
                    p.url +="/?"+string.Join("&",datalist);

                }
                var rawdata = item.Operation.Parameters
                     .Where(s => s.Kind == SwaggerParameterKind.Body)
                     .SingleOrDefault();
                if (rawdata!=null)
                {
                   
                    p.dataMode = "raw";
                    p.rawModeData =new Schema4Json().ToSampleJson(rawdata.ActualSchema);
                    //美化
                    p.rawModeData = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(p.rawModeData),Formatting.Indented);

                    if (string.IsNullOrEmpty(p.headers)||(!string.IsNullOrEmpty(p.headers)&&!p.headers.Contains("Content-Type: application/json\n")))
                    {
                        p.headers = "Content-Type: application/json\n" + p.headers??"";
                    }
                }
                
               
                re.Add(p);
            }
            return re;
        }
Example #2
0
        private List <PostmanRequest> GetPostmanRequests(IEnumerable <SwaggerOperationDescription> apis, string collectionId, string root, SwaggerToolSettings setting)
        {
            List <PostmanRequest> re = new List <PostmanRequest>();

            foreach (var item in apis)
            {
                var p = new PostmanRequest
                {
                    id                = PostMan.GetId(),
                    name              = item.Operation.Summary,
                    description       = item.Operation.Summary,
                    descriptionFormat = "html",
                    headers           = setting.PostmanGen.headers,
                    method            = item.Method.ToString().ToUpper(),
                    pathVariables     = new Dictionary <string, string>(),
                    url               = root + item.Path,
                    collectionId      = collectionId,
                    tagname           = item.Operation.Tags.FirstOrDefault()
                };
                var datalist = item.Operation.Parameters
                               .Where(s => s.Kind == SwaggerParameterKind.Query)
                               .Select(s => s.Name + "={{" + s.Name + "}}")
                               .ToList();

                if (datalist.Count > 0)
                {
                    p.dataMode = "params";
                    //URL Query
                    p.url += "/?" + string.Join("&", datalist);
                }
                var rawdata = item.Operation.Parameters
                              .Where(s => s.Kind == SwaggerParameterKind.Body)
                              .SingleOrDefault();
                if (rawdata != null)
                {
                    p.dataMode    = "raw";
                    p.rawModeData = new Schema4Json().ToSampleJson(rawdata.ActualSchema);
                    //美化
                    p.rawModeData = JsonConvert.SerializeObject(JsonConvert.DeserializeObject(p.rawModeData), Formatting.Indented);

                    if (string.IsNullOrEmpty(p.headers) || (!string.IsNullOrEmpty(p.headers) && !p.headers.Contains("Content-Type: application/json\n")))
                    {
                        p.headers = "Content-Type: application/json\n" + p.headers ?? "";
                    }
                }


                re.Add(p);
            }
            return(re);
        }