private OpenApiToCSharpCode.OpenApi2 getOpenApi2ByFile(OpenApiToCSharpCode.Class1 aaaa, string filePath) { var file = System.IO.File.ReadAllText(filePath); var url = aaaa.GetOpenApi2(file); return(url); }
private void button1_Click(object sender, EventArgs e) { //var url2 = "https://developer.ebay.com/api-docs/master/buy/browse/openapi/2/buy_browse_v1_beta_oas2.json"; //var url3 = "https://developer.ebay.com/api-docs/master/buy/browse/openapi/3/buy_browse_v1_beta_oas3.json"; //var client = new RestSharp.RestClient("https://developer.ebay.com/"); //var data = client.Execute(new RestSharp.RestRequest(url2)); //var sdd = Newtonsoft.Json.JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JObject>(data.Content); var aaa = new Dictionary <System.Tuple <string, string, string>, string>() { //{ Tuple.Create("eBayApi.Buy.Test","TestClient","Test"), "Api文档/m6594_Test-Petstore_1.0.0_swagger.json" }, { Tuple.Create("eBayApi.Buy.Browse", "BrowseClient", "Browse"), "Api文档/buy_browse_v1_beta_oas2.json" }, { Tuple.Create("eBayApi.Buy.Feed", "FeedClient", "Feed"), "Api文档/buy_feed_v1_beta_oas2.json" }, { Tuple.Create("eBayApi.Buy.Marketing", "MarketingClient", "Marketing"), "Api文档/buy_marketing_v1_beta_oas2.json" }, //{ Tuple.Create("eBayApi.Buy.Order","OrderClient"), "Api文档/buy_order_v1_beta_oas3.json" }, { Tuple.Create("eBayApi.Commerce.Catalog", "CatalogClient", "Catalog"), "Api文档/commerce_catalog_v1_beta_oas2.json" }, { Tuple.Create("eBayApi.Commerce.Taxonomy", "TaxonomyClient", "Taxonomy"), "Api文档/commerce_taxonomy_v1_beta_oas2.json" }, { Tuple.Create("eBayApi.Sell.Compliance", "ComplianceClient", "Compliance"), "Api文档/sell_compliance_v1_oas2.json" }, { Tuple.Create("eBayApi.Sell.Fulfillment", "FulfillmentClient", "Fulfillment"), "Api文档/sell_fulfillment_v1_oas2.json" } }; var aaaa = new OpenApiToCSharpCode.Class1(); var bbb = aaa.Select(f => new { Doc = f, OpenApi = getOpenApi2ByFile(aaaa, f.Value) }).ToArray(); var code = string.Join("\r\n", new[] { "//------------------------------------------------------------------------------", "// <auto-generated>", "// 此代码由工具生成。", "// 运行时版本:" + Environment.Version, "//", "// 对此文件的更改可能会导致不正确的行为,并且如果", "// 重新生成代码,这些更改将会丢失。", "// </auto-generated>", "//------------------------------------------------------------------------------", "", "using System;", "using System.Collections.Generic;", "using System.Text; ", "using System.Runtime.Serialization;", "using Newtonsoft.Json;", "using RestSharp;", }) + "\r\n"; code += aaaa.GetClientCode(bbb.Select(f => Tuple.Create(f.Doc.Key.Item1, f.Doc.Key.Item2, f.Doc.Key.Item3, f.OpenApi.Schemes?.FirstOrDefault() + "://" + f.OpenApi.Host + f.OpenApi.BasePath)).ToArray(), "eBayApi", "eBayClient"); foreach (var item in bbb) { var ddddddd0 = aaaa.GetMethodCode(item.OpenApi, item.Doc.Key.Item1, item.Doc.Key.Item2); var ddddddd1 = aaaa.GetModelCode(item.OpenApi, item.Doc.Key.Item1); //var ddddddd2 = GetMarkdownFile(url, item.Key); code += ddddddd0 + "\r\n"; code += ddddddd1 + "\r\n"; } }