public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseCloudFoundryHosting(APIConfig.GetInstance().Port) //部署在linux上才生效,接口的端口配置 .UseStartup <Startup>() .UseUrls($"http://0.0.0.0:{APIConfig.GetInstance().Port}") //部署在linux上才生效,接口的端口配置 .Build();
public BaseExtractor(APIConfig config) { this.config = config; }
private Func <CommandEventArgs, Task> APIQuery(APIConfig config) => async e => { //get the parameter var query = e.GetArg("query")?.Trim(); if (string.IsNullOrWhiteSpace(query) && !config.AllowEmpty) { await e.Channel.SendMessage("Query must be provided"); return; } //replace any characters or forbidden things foreach (var replacer in config.QueryReplacements) { query = Regex.Replace(query, replacer.Key, x => replacer.Value); } var link = config.URL + Uri.EscapeDataString(query) + Regex.Replace(config.URLSuffix, @"%(\d+)random(\d+)%", x => Range.Next(int.Parse(x.Groups[1].Value), int.Parse(x.Groups[2].Value)) + ""); var response = await SearchHelper.GetResponseStringAsync(link, config.Headers).ConfigureAwait(false); string message = ""; //Get our message switch (config.ResponseHandling.Item1) { case "JSON": JToken obj = JObject.Parse(response); message = getJsonToken(config.ResponseHandling.Item2, obj).ToString(); break; case "XDOC": var doc = XDocument.Load(response); message = doc.Descendants(config.ResponseHandling.Item2).FirstOrDefault().Value; break; case "REGEX": var matches = Regex.Matches(response, config.ResponseHandling.Item2); if (matches.Count == 0) { await e.Channel.SendMessage("responsehandling failed").ConfigureAwait(false); return; } else { message = matches[Range.Next(0, matches.Count)].Value; } break; default: await e.Channel.SendMessage("Response handling not specified!").ConfigureAwait(false); return; } //Change anything that needs to be changed foreach (var reg in config.RegexOnResponse) { message = Regex.Replace(message, reg.Key, x => reg.Value); } if (string.IsNullOrWhiteSpace(message)) { await e.Channel.SendMessage("Something went wrong, no message left").ConfigureAwait(false); return; } await e.Channel.SendMessage(message).ConfigureAwait(false); };
public ErrorTest() { config = APIConfig.FromJsonFile("configUSA_Error.json"); client = new APIClient(config); }
public SendMessageRequest(APIConfig config) : base(config) { }
public HttpExtractor(APIConfig config) : base(config) { client.Timeout = TimeSpan.FromMilliseconds(config.Connection.RequestTimeoutMs); }
public CheckLimitRequest(APIConfig config) : base(config) { }
public static string MakeResourceName(APIConfig api) { return($"[concat(parameters('{ParameterNames.ApimServiceName}'), '/{api.name}')]"); }
private IEnumerator LoadData(string siteName) { ClearUI(); var databases = new List <WordCloudDatabase>(); message.text = Translator.Get("Loading data") + " ..."; message.gameObject.SetActive(true); yield return(null); var wordCloudPath = Paths.Data + "WordCloud"; var path = wordCloudPath + Path.DirectorySeparatorChar + siteName; if (Directory.Exists(path)) { var files = Directory.GetFiles(path, "*.csv"); for (int i = 0; i < files.Length; ++i) { yield return(SurveyConfig.Load(files[i], (s) => { if (s != null) { s.name = Path.GetFileNameWithoutExtension(files[i]); databases.Add(s); } })); } } // connecting to API var configAPIPath = Paths.Data + "api.csv"; API[] apis = null; yield return(APIConfig.Load(configAPIPath, (a) => apis = a)); if (apis != null) { for (int i = 0; i < apis.Length; ++i) { // check if site name is as currect or empty what is mark for global data if (apis[i].site.Contains(siteName) || apis[i].site == "*") { yield return(WordCloudDatabase.LoadDataFromAPI(apis[i], (db) => databases.Add(db))); } } } if (databases.Count > 0) { message.gameObject.SetActive(false); groupToggle.interactable = true; CreateDataUI(databases); } else { groupToggle.interactable = false; message.text = Translator.Get("There's no data available for this site"); if (Directory.Exists(wordCloudPath)) { var dataManager = ComponentManager.Instance.Get <DataManager>(); var dirs = Directory.GetDirectories(wordCloudPath); var examples = "\n" + Translator.Get("The folowing sites have data") + ": "; bool haveExamples = false; foreach (var dir in dirs) { var dirName = dir.Substring(wordCloudPath.Length + 1); if (dataManager.HasSite(dirName)) { examples += dirName + ", "; haveExamples = true; } } if (haveExamples) { message.text += examples.Substring(0, examples.Length - 2); } } } loadCR = null; }
public void ShouldCreateProductAPIFromCreatorConfig() { // arrange ProductAPITemplateCreator productAPITemplateCreator = new ProductAPITemplateCreator(new TemplateBuilder()); CreatorConfig creatorConfig = new CreatorConfig() { products = new List <ProductConfig>(), apis = new List <APIConfig>() }; ProductConfig product = new ProductConfig() { Name = "productName", DisplayName = "display name", Description = "description", Terms = "terms", SubscriptionRequired = true, ApprovalRequired = true, SubscriptionsLimit = 1, State = "state" }; creatorConfig.products.Add(product); APIConfig api = new APIConfig() { name = "apiName", apiVersion = "apiVersion", apiVersionDescription = "apiVersionDescription", apiVersionSetId = "apiVersionSetId", apiRevision = "revision", apiRevisionDescription = "revisionDescription", suffix = "suffix", products = "productName", subscriptionRequired = true, authenticationSettings = new APITemplateAuthenticationSettings() { OAuth2 = new APITemplateOAuth2() { AuthorizationServerId = "", Scope = "" }, Openid = new APITemplateOpenID() { OpenIdProviderId = "", BearerTokenSendingMethods = new string[] { } }, SubscriptionKeyRequired = true }, openApiSpec = "https://petstore.swagger.io/v2/swagger.json", protocols = "https", isCurrent = true, type = "http" }; creatorConfig.apis.Add(api); // act Template productAPITemplate = productAPITemplateCreator.CreateProductAPITemplate(creatorConfig); ProductApiTemplateResource productAPITemplateResource = (ProductApiTemplateResource)productAPITemplate.Resources[0]; // assert Assert.Equal($"[concat(parameters('{ParameterNames.ApimServiceName}'), '/{product.Name}/{api.name}')]", productAPITemplateResource.Name); }
/// <summary> /// Constructors a new SecurityHeader /// </summary> /// <param name="config"><see cref="APIConfig"/></param> public SecurityHeader(APIConfig config) { this.config = config; }
string MakeServiceUrl(APIConfig api) { return(!string.IsNullOrEmpty(api.serviceUrl) ? $"[parameters('{api.name + "-ServiceUrl"}')]" : null); }
public bool IsSplitAPI(APIConfig apiConfig) { // the api needs to be split into multiple templates if the user has supplied a version or version set - deploying swagger related properties at the same time as api version related properties fails, so they must be written and deployed separately return(apiConfig.apiVersion != null || apiConfig.apiVersionSetId != null || apiConfig.authenticationSettings != null && apiConfig.authenticationSettings.OAuth2 != null && apiConfig.authenticationSettings.OAuth2.AuthorizationServerId != null); }
public async Task ExecuteCommandAsync(CreatorConfig creatorConfig) { FileReader fileReader = new FileReader(); // initialize file helper classes FileNames fileNames = creatorConfig.baseFileName == null ? FileNameGenerator.GenerateFileNames(creatorConfig.apimServiceName) : FileNameGenerator.GenerateFileNames(creatorConfig.baseFileName); // initialize template creator classes APIVersionSetTemplateCreator apiVersionSetTemplateCreator = new APIVersionSetTemplateCreator(this.templateBuilder); LoggerTemplateCreator loggerTemplateCreator = new LoggerTemplateCreator(this.templateBuilder); BackendTemplateCreator backendTemplateCreator = new BackendTemplateCreator(this.templateBuilder); AuthorizationServerTemplateCreator authorizationServerTemplateCreator = new AuthorizationServerTemplateCreator(this.templateBuilder); ProductAPITemplateCreator productAPITemplateCreator = new ProductAPITemplateCreator(this.templateBuilder); TagAPITemplateCreator tagAPITemplateCreator = new TagAPITemplateCreator(); PolicyTemplateCreator policyTemplateCreator = new PolicyTemplateCreator(fileReader, this.templateBuilder); ProductGroupTemplateCreator productGroupTemplateCreator = new ProductGroupTemplateCreator(); SubscriptionTemplateCreator productSubscriptionsTemplateCreator = new SubscriptionTemplateCreator(); DiagnosticTemplateCreator diagnosticTemplateCreator = new DiagnosticTemplateCreator(); ReleaseTemplateCreator releaseTemplateCreator = new ReleaseTemplateCreator(); ProductTemplateCreator productTemplateCreator = new ProductTemplateCreator(policyTemplateCreator, productGroupTemplateCreator, productSubscriptionsTemplateCreator, this.templateBuilder); PropertyTemplateCreator propertyTemplateCreator = new PropertyTemplateCreator(this.templateBuilder); TagTemplateCreator tagTemplateCreator = new TagTemplateCreator(this.templateBuilder); APITemplateCreator apiTemplateCreator = new APITemplateCreator(fileReader, policyTemplateCreator, productAPITemplateCreator, tagAPITemplateCreator, diagnosticTemplateCreator, releaseTemplateCreator, this.templateBuilder); MasterTemplateCreator masterTemplateCreator = new MasterTemplateCreator(this.templateBuilder); // create templates from provided configuration Console.WriteLine("Creating global service policy template"); Console.WriteLine("------------------------------------------"); Template globalServicePolicyTemplate = creatorConfig.policy != null?policyTemplateCreator.CreateGlobalServicePolicyTemplate(creatorConfig) : null; Console.WriteLine("Creating API version set template"); Console.WriteLine("------------------------------------------"); Template apiVersionSetsTemplate = creatorConfig.apiVersionSets != null?apiVersionSetTemplateCreator.CreateAPIVersionSetTemplate(creatorConfig) : null; Console.WriteLine("Creating product template"); Console.WriteLine("------------------------------------------"); Template productsTemplate = creatorConfig.products != null?productTemplateCreator.CreateProductTemplate(creatorConfig) : null; Console.WriteLine("Creating product/APIs template"); Console.WriteLine("------------------------------------------"); Template productAPIsTemplate = creatorConfig.products != null && creatorConfig.apis != null?productAPITemplateCreator.CreateProductAPITemplate(creatorConfig) : null; Console.WriteLine("Creating named values template"); Console.WriteLine("------------------------------------------"); Template propertyTemplate = creatorConfig.namedValues != null?propertyTemplateCreator.CreatePropertyTemplate(creatorConfig) : null; Console.WriteLine("Creating logger template"); Console.WriteLine("------------------------------------------"); Template loggersTemplate = creatorConfig.loggers != null?loggerTemplateCreator.CreateLoggerTemplate(creatorConfig) : null; Console.WriteLine("Creating backend template"); Console.WriteLine("------------------------------------------"); Template backendsTemplate = creatorConfig.backends != null?backendTemplateCreator.CreateBackendTemplate(creatorConfig) : null; Console.WriteLine("Creating authorization server template"); Console.WriteLine("------------------------------------------"); Template authorizationServersTemplate = creatorConfig.authorizationServers != null?authorizationServerTemplateCreator.CreateAuthorizationServerTemplate(creatorConfig) : null; // store name and whether the api will depend on the version set template each api necessary to build linked templates List <LinkedMasterTemplateAPIInformation> apiInformation = new List <LinkedMasterTemplateAPIInformation>(); List <Template> apiTemplates = new List <Template>(); Console.WriteLine("Creating API templates"); Console.WriteLine("------------------------------------------"); IDictionary <string, string[]> apiVersions = APITemplateCreator.GetApiVersionSets(creatorConfig); foreach (APIConfig api in creatorConfig.apis) { if (creatorConfig.ConsiderAllApiForDeployments || creatorConfig.PreferredApis.Contains(api.name)) { bool isServiceUrlParameterizeInYml = false; if (creatorConfig.serviceUrlParameters != null && creatorConfig.serviceUrlParameters.Count > 0) { isServiceUrlParameterizeInYml = creatorConfig.serviceUrlParameters.Any(s => s.ApiName.Equals(api.name)); api.serviceUrl = isServiceUrlParameterizeInYml ? creatorConfig.serviceUrlParameters.Where(s => s.ApiName.Equals(api.name)).FirstOrDefault().ServiceUrl : api.serviceUrl; } // create api templates from provided api config - if the api config contains a supplied apiVersion, split the templates into 2 for metadata and swagger content, otherwise create a unified template List <Template> apiTemplateSet = await apiTemplateCreator.CreateAPITemplatesAsync(api); apiTemplates.AddRange(apiTemplateSet); // create the relevant info that will be needed to properly link to the api template(s) from the master template apiInformation.Add(new LinkedMasterTemplateAPIInformation() { name = api.name, isSplit = apiTemplateCreator.IsSplitAPI(api), dependsOnGlobalServicePolicies = creatorConfig.policy != null, dependsOnVersionSets = api.apiVersionSetId != null, dependsOnVersion = masterTemplateCreator.GetDependsOnPreviousApiVersion(api, apiVersions), dependsOnProducts = api.products != null, dependsOnTags = api.tags != null, dependsOnLoggers = await masterTemplateCreator.DetermineIfAPIDependsOnLoggerAsync(api, fileReader), dependsOnAuthorizationServers = api.authenticationSettings != null && api.authenticationSettings.OAuth2 != null && api.authenticationSettings.OAuth2.AuthorizationServerId != null, dependsOnBackends = await masterTemplateCreator.DetermineIfAPIDependsOnBackendAsync(api, fileReader), isServiceUrlParameterize = isServiceUrlParameterizeInYml }); } } Console.WriteLine("Creating tag template"); Console.WriteLine("------------------------------------------"); Template tagTemplate = creatorConfig.tags != null?tagTemplateCreator.CreateTagTemplate(creatorConfig) : null; // create parameters file Template templateParameters = masterTemplateCreator.CreateMasterTemplateParameterValues(creatorConfig); // write templates to outputLocation if (creatorConfig.linked == true) { // create linked master template Template masterTemplate = masterTemplateCreator.CreateLinkedMasterTemplate(creatorConfig, globalServicePolicyTemplate, apiVersionSetsTemplate, productsTemplate, productAPIsTemplate, propertyTemplate, loggersTemplate, backendsTemplate, authorizationServersTemplate, tagTemplate, apiInformation, fileNames, creatorConfig.apimServiceName); FileWriter.WriteJSONToFile(masterTemplate, string.Concat(creatorConfig.outputLocation, fileNames.LinkedMaster)); } foreach (Template apiTemplate in apiTemplates) { APITemplateResource apiResource = apiTemplate.Resources.FirstOrDefault(resource => resource.Type == ResourceTypeConstants.API) as APITemplateResource; APIConfig providedAPIConfiguration = creatorConfig.apis.FirstOrDefault(api => string.Compare(apiResource.Name, APITemplateCreator.MakeResourceName(api), true) == 0); // if the api version is not null the api is split into multiple templates. If the template is split and the content value has been set, then the template is for a subsequent api string apiFileName = FileNameGenerator.GenerateCreatorAPIFileName(providedAPIConfiguration.name, apiTemplateCreator.IsSplitAPI(providedAPIConfiguration), apiResource.Properties.Value != null); FileWriter.WriteJSONToFile(apiTemplate, string.Concat(creatorConfig.outputLocation, apiFileName)); } if (globalServicePolicyTemplate != null) { FileWriter.WriteJSONToFile(globalServicePolicyTemplate, string.Concat(creatorConfig.outputLocation, fileNames.GlobalServicePolicy)); } if (apiVersionSetsTemplate != null) { FileWriter.WriteJSONToFile(apiVersionSetsTemplate, string.Concat(creatorConfig.outputLocation, fileNames.ApiVersionSets)); } if (productsTemplate != null) { FileWriter.WriteJSONToFile(productsTemplate, string.Concat(creatorConfig.outputLocation, fileNames.Products)); } if (productAPIsTemplate != null) { FileWriter.WriteJSONToFile(productAPIsTemplate, string.Concat(creatorConfig.outputLocation, fileNames.ProductAPIs)); } if (propertyTemplate != null) { FileWriter.WriteJSONToFile(propertyTemplate, string.Concat(creatorConfig.outputLocation, fileNames.NamedValues)); } if (loggersTemplate != null) { FileWriter.WriteJSONToFile(loggersTemplate, string.Concat(creatorConfig.outputLocation, fileNames.Loggers)); } if (backendsTemplate != null) { FileWriter.WriteJSONToFile(backendsTemplate, string.Concat(creatorConfig.outputLocation, fileNames.Backends)); } if (authorizationServersTemplate != null) { FileWriter.WriteJSONToFile(authorizationServersTemplate, string.Concat(creatorConfig.outputLocation, fileNames.AuthorizationServers)); } if (tagTemplate != null) { FileWriter.WriteJSONToFile(tagTemplate, string.Concat(creatorConfig.outputLocation, fileNames.Tags)); } // write parameters to outputLocation FileWriter.WriteJSONToFile(templateParameters, string.Concat(creatorConfig.outputLocation, fileNames.Parameters)); Console.WriteLine("Templates written to output location"); }
public async void ShouldCreateUnifiedAPITemplateResourceFromCreatorConfig() { // arrange APITemplateCreator apiTemplateCreator = APITemplateCreatorFactory.GenerateAPITemplateCreator(); CreatorConfig creatorConfig = new CreatorConfig() { apis = new List <APIConfig>() }; APIConfig api = new APIConfig() { name = "name", apiVersion = "apiVersion", apiVersionDescription = "apiVersionDescription", apiVersionSetId = "apiVersionSetId", apiRevision = "revision", apiRevisionDescription = "revisionDescription", suffix = "suffix", subscriptionRequired = true, authenticationSettings = new APITemplateAuthenticationSettings() { OAuth2 = new APITemplateOAuth2() { AuthorizationServerId = "", Scope = "" }, Openid = new APITemplateOpenID() { OpenIdProviderId = "", BearerTokenSendingMethods = new string[] { } }, SubscriptionKeyRequired = true }, openApiSpec = "https://petstore.swagger.io/v2/swagger.json", protocols = "https", isCurrent = true, type = "http" }; creatorConfig.apis.Add(api); // act APITemplateResource apiTemplateResource = await apiTemplateCreator.CreateAPITemplateResourceAsync(api, false, true); // assert Assert.Equal($"[concat(parameters('{ParameterNames.ApimServiceName}'), '/{api.name}')]", apiTemplateResource.Name); Assert.Equal(api.name, apiTemplateResource.Properties.DisplayName); Assert.Equal(api.apiVersion, apiTemplateResource.Properties.ApiVersion); Assert.Equal(api.type, apiTemplateResource.Properties.Type); Assert.Equal(api.type, apiTemplateResource.Properties.ApiType); Assert.Equal(api.isCurrent, apiTemplateResource.Properties.IsCurrent); Assert.Equal(new string[] { api.protocols }, apiTemplateResource.Properties.Protocols); Assert.Equal(api.apiVersionDescription, apiTemplateResource.Properties.ApiVersionDescription); Assert.Equal($"[resourceId('Microsoft.ApiManagement/service/apiVersionSets', parameters('{ParameterNames.ApimServiceName}'), '{api.apiVersionSetId}')]", apiTemplateResource.Properties.ApiVersionSetId); Assert.Equal(api.apiRevision, apiTemplateResource.Properties.ApiRevision); Assert.Equal(api.apiRevisionDescription, apiTemplateResource.Properties.ApiRevisionDescription); Assert.Equal(api.suffix, apiTemplateResource.Properties.Path); Assert.Equal(api.subscriptionRequired, apiTemplateResource.Properties.SubscriptionRequired); Assert.Equal(api.authenticationSettings.OAuth2.AuthorizationServerId, apiTemplateResource.Properties.AuthenticationSettings.OAuth2.AuthorizationServerId); Assert.Equal(api.authenticationSettings.OAuth2.Scope, apiTemplateResource.Properties.AuthenticationSettings.OAuth2.Scope); Assert.Equal(api.authenticationSettings.Openid.OpenIdProviderId, apiTemplateResource.Properties.AuthenticationSettings.Openid.OpenIdProviderId); Assert.Equal(api.authenticationSettings.Openid.BearerTokenSendingMethods, apiTemplateResource.Properties.AuthenticationSettings.Openid.BearerTokenSendingMethods); Assert.Equal(api.authenticationSettings.SubscriptionKeyRequired, apiTemplateResource.Properties.AuthenticationSettings.SubscriptionKeyRequired); Assert.Equal("swagger-link-json", apiTemplateResource.Properties.Format); Assert.Equal(api.openApiSpec, apiTemplateResource.Properties.Value); }
public BaseRequest(APIConfig config) => this.config = config;
public async Task <APITemplateResource> CreateAPITemplateResourceAsync(APIConfig api, bool isSplit, bool isInitial) { // create api resource APITemplateResource apiTemplateResource = new APITemplateResource() { Name = MakeResourceName(api), Type = ResourceTypeConstants.API, ApiVersion = GlobalConstants.ApiVersion, Properties = new APITemplateProperties(), DependsOn = new string[] { } }; // add properties depending on whether the template is the initial, subsequent, or unified if (!isSplit || !isInitial) { // add metadata properties for initial and unified templates apiTemplateResource.Properties.ApiVersion = api.apiVersion; apiTemplateResource.Properties.ServiceUrl = this.MakeServiceUrl(api); apiTemplateResource.Properties.Type = api.type; apiTemplateResource.Properties.ApiType = api.type; apiTemplateResource.Properties.Description = api.description; apiTemplateResource.Properties.SubscriptionRequired = api.subscriptionRequired; apiTemplateResource.Properties.ApiRevision = api.apiRevision; apiTemplateResource.Properties.ApiRevisionDescription = api.apiRevisionDescription; apiTemplateResource.Properties.ApiVersionDescription = api.apiVersionDescription; apiTemplateResource.Properties.AuthenticationSettings = api.authenticationSettings; apiTemplateResource.Properties.SubscriptionKeyParameterNames = api.subscriptionKeyParameterNames; apiTemplateResource.Properties.Path = api.suffix; apiTemplateResource.Properties.IsCurrent = api.isCurrent; apiTemplateResource.Properties.DisplayName = string.IsNullOrEmpty(api.displayName) ? api.name : api.displayName; apiTemplateResource.Properties.Protocols = this.CreateProtocols(api); // set the version set id if (api.apiVersionSetId != null) { // point to the supplied version set if the apiVersionSetId is provided apiTemplateResource.Properties.ApiVersionSetId = $"[resourceId('Microsoft.ApiManagement/service/apiVersionSets', parameters('{ParameterNames.ApimServiceName}'), '{api.apiVersionSetId}')]"; } // set the authorization server id if (api.authenticationSettings != null && api.authenticationSettings.OAuth2 != null && api.authenticationSettings.OAuth2.AuthorizationServerId != null && apiTemplateResource.Properties.AuthenticationSettings != null && apiTemplateResource.Properties.AuthenticationSettings.OAuth2 != null && apiTemplateResource.Properties.AuthenticationSettings.OAuth2.AuthorizationServerId != null) { apiTemplateResource.Properties.AuthenticationSettings.OAuth2.AuthorizationServerId = api.authenticationSettings.OAuth2.AuthorizationServerId; } // set the subscriptionKey Parameter Names if (api.subscriptionKeyParameterNames != null) { if (api.subscriptionKeyParameterNames.Header != null) { apiTemplateResource.Properties.SubscriptionKeyParameterNames.Header = api.subscriptionKeyParameterNames.Header; } if (api.subscriptionKeyParameterNames.Query != null) { apiTemplateResource.Properties.SubscriptionKeyParameterNames.Query = api.subscriptionKeyParameterNames.Query; } } } if (!isSplit || isInitial) { // add open api spec properties for subsequent and unified templates string format; string value; // determine if the open api spec is remote or local, yaml or json bool isJSON = false; bool isUrl = IsUri(api, out var _); string fileContents = null; if (!isUrl || api.openApiSpecFormat == OpenApiSpecFormat.Unspecified) { fileContents = await this.fileReader.RetrieveFileContentsAsync(api.openApiSpec); } value = isUrl ? api.openApiSpec : fileContents ; bool isVersionThree = false; if (api.openApiSpecFormat == OpenApiSpecFormat.Unspecified) { isJSON = this.fileReader.IsJSON(fileContents); if (isJSON == true) { var openAPISpecReader = new OpenAPISpecReader(); isVersionThree = await openAPISpecReader.IsJSONOpenAPISpecVersionThreeAsync(api.openApiSpec); } format = GetOpenApiSpecFormat(isUrl, isJSON, isVersionThree); } else { isJSON = IsOpenApiSpecJson(api.openApiSpecFormat); format = GetOpenApiSpecFormat(isUrl, api.openApiSpecFormat); } // if the title needs to be modified // we need to embed the OpenAPI definition if (!string.IsNullOrEmpty(api.displayName)) { format = GetOpenApiSpecFormat(false, isJSON, isVersionThree); // download definition if (isUrl) { using (var client = new WebClient()) value = client.DownloadString(value); } // update title value = new OpenApi(value, format) .SetTitle(api.displayName) .GetDefinition() ; } // set the version set id if (api.apiVersionSetId != null) { // point to the supplied version set if the apiVersionSetId is provided apiTemplateResource.Properties.ApiVersionSetId = $"[resourceId('Microsoft.ApiManagement/service/apiVersionSets', parameters('{ParameterNames.ApimServiceName}'), '{api.apiVersionSetId}')]"; } apiTemplateResource.Properties.Format = format; apiTemplateResource.Properties.Value = value; // #562: deploying multiple versions of an API may fail because while trying to deploy the initial template // overwrite the initial template’s path property to a dummy value // this value will be restored when the subsequent template is deployed if (isSplit && isInitial) { apiTemplateResource.Properties.Path = api.suffix + $"/{Guid.NewGuid():n}"; } else { apiTemplateResource.Properties.Path = api.suffix; } if (!string.IsNullOrEmpty(api.serviceUrl)) { apiTemplateResource.Properties.ServiceUrl = this.MakeServiceUrl(api); } } return(apiTemplateResource); }