|
4 | 4 | using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Common;
|
5 | 5 | using apimtemplate.Creator.Utilities;
|
6 | 6 | using System.Net;
|
| 7 | +using Microsoft.Azure.Management.ApiManagement.ArmTemplates.Extract; |
7 | 8 |
|
8 | 9 | namespace Microsoft.Azure.Management.ApiManagement.ArmTemplates.Create
|
9 | 10 | {
|
@@ -68,6 +69,11 @@ public async Task<Template> CreateAPITemplateAsync(APIConfig api, bool isSplit,
|
68 | 69 | { ParameterNames.ApimServiceName, new TemplateParameterProperties(){ type = "string" } }
|
69 | 70 | };
|
70 | 71 |
|
| 72 | + if (String.IsNullOrEmpty(api.serviceUrl)) |
| 73 | + { |
| 74 | + apiTemplate.parameters.Add(ParameterNames.ServiceUrl, new TemplateParameterProperties() { type = "object" }); |
| 75 | + } |
| 76 | + |
71 | 77 | List<TemplateResource> resources = new List<TemplateResource>();
|
72 | 78 | // create api resource
|
73 | 79 | APITemplateResource apiTemplateResource = await this.CreateAPITemplateResourceAsync(api, isSplit, isInitial);
|
@@ -124,7 +130,7 @@ public async Task<APITemplateResource> CreateAPITemplateResourceAsync(APIConfig
|
124 | 130 | {
|
125 | 131 | // add metadata properties for initial and unified templates
|
126 | 132 | apiTemplateResource.properties.apiVersion = api.apiVersion;
|
127 |
| - apiTemplateResource.properties.serviceUrl = api.serviceUrl; |
| 133 | + apiTemplateResource.properties.serviceUrl = MakeServiceUrl(api); |
128 | 134 | apiTemplateResource.properties.type = api.type;
|
129 | 135 | apiTemplateResource.properties.apiType = api.type;
|
130 | 136 | apiTemplateResource.properties.description = api.description;
|
@@ -224,8 +230,8 @@ public async Task<APITemplateResource> CreateAPITemplateResourceAsync(APIConfig
|
224 | 230 | apiTemplateResource.properties.format = format;
|
225 | 231 | apiTemplateResource.properties.value = value;
|
226 | 232 | apiTemplateResource.properties.path = api.suffix;
|
227 |
| - apiTemplateResource.properties.serviceUrl = api.serviceUrl; |
228 |
| - |
| 233 | + apiTemplateResource.properties.serviceUrl = MakeServiceUrl(api); |
| 234 | + |
229 | 235 | }
|
230 | 236 | return apiTemplateResource;
|
231 | 237 | }
|
@@ -254,5 +260,10 @@ public bool isSplitAPI(APIConfig apiConfig)
|
254 | 260 | // 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
|
255 | 261 | return apiConfig.apiVersion != null || apiConfig.apiVersionSetId != null || (apiConfig.authenticationSettings != null && apiConfig.authenticationSettings.oAuth2 != null && apiConfig.authenticationSettings.oAuth2.authorizationServerId != null);
|
256 | 262 | }
|
| 263 | + |
| 264 | + private string MakeServiceUrl(APIConfig api) |
| 265 | + { |
| 266 | + return api.serviceUrl ?? $"[parameters('{ParameterNames.ServiceUrl}').{ExtractorUtils.GenValidParamName(api.name, ParameterPrefix.Api)}]"; |
| 267 | + } |
257 | 268 | }
|
258 | 269 | }
|
0 commit comments