Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 0a4b5dc

Browse files
authored
generated filename changes: if baseFileName is blank, skip "-", remove apim instance name from api filename (#364)
1 parent 2e68fb4 commit 0a4b5dc

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

src/APIM_ARMTemplate/apimtemplate/Commands/Create.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public CreateCommand()
116116
APITemplateResource apiResource = apiTemplate.resources.FirstOrDefault(resource => resource.type == ResourceTypeConstants.API) as APITemplateResource;
117117
APIConfig providedAPIConfiguration = creatorConfig.apis.FirstOrDefault(api => apiResource.name.Contains(api.name, StringComparison.Ordinal));
118118
// 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
119-
string apiFileName = fileNameGenerator.GenerateCreatorAPIFileName(providedAPIConfiguration.name, apiTemplateCreator.isSplitAPI(providedAPIConfiguration), apiResource.properties.value != null, creatorConfig.apimServiceName);
119+
string apiFileName = fileNameGenerator.GenerateCreatorAPIFileName(providedAPIConfiguration.name, apiTemplateCreator.isSplitAPI(providedAPIConfiguration), apiResource.properties.value != null);
120120
fileWriter.WriteJSONToFile(apiTemplate, String.Concat(creatorConfig.outputLocation, apiFileName));
121121
}
122122
if (globalServicePolicyTemplate != null)

src/APIM_ARMTemplate/apimtemplate/Common/FileHandlers/FileNameGenerator.cs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@ public class FileNameGenerator
77

88
public FileNames GenerateFileNames(string baseFileName)
99
{
10+
if (baseFileName.Length > 0)
11+
baseFileName += "-";
12+
1013
// generate useable object with file names for consistency throughout project
1114
return new FileNames()
1215
{
13-
apiVersionSets = $@"/{baseFileName}-apiVersionSets.template.json",
14-
authorizationServers = $@"/{baseFileName}-authorizationServers.template.json",
15-
backends = $@"/{baseFileName}-backends.template.json",
16-
globalServicePolicy = $@"/{baseFileName}-globalServicePolicy.template.json",
17-
loggers = $@"/{baseFileName}-loggers.template.json",
18-
namedValues = $@"/{baseFileName}-namedValues.template.json",
19-
tags = $@"/{baseFileName}-tags.template.json",
20-
products = $@"/{baseFileName}-products.template.json",
21-
parameters = $@"/{baseFileName}-parameters.json",
22-
linkedMaster = $@"/{baseFileName}-master.template.json",
16+
apiVersionSets = $@"/{baseFileName}apiVersionSets.template.json",
17+
authorizationServers = $@"/{baseFileName}authorizationServers.template.json",
18+
backends = $@"/{baseFileName}backends.template.json",
19+
globalServicePolicy = $@"/{baseFileName}globalServicePolicy.template.json",
20+
loggers = $@"/{baseFileName}loggers.template.json",
21+
namedValues = $@"/{baseFileName}namedValues.template.json",
22+
tags = $@"/{baseFileName}tags.template.json",
23+
products = $@"/{baseFileName}products.template.json",
24+
parameters = $@"/{baseFileName}parameters.json",
25+
linkedMaster = $@"/{baseFileName}master.template.json",
2326
apis = "/Apis",
2427
splitAPIs = "/SplitAPIs",
2528
versionSetMasterFolder = "/VersionSetMasterFolder",
@@ -29,23 +32,27 @@ public FileNames GenerateFileNames(string baseFileName)
2932
};
3033
}
3134

32-
public string GenerateCreatorAPIFileName(string apiName, bool isSplitAPI, bool isInitialAPI, string apimServiceName)
35+
public string GenerateCreatorAPIFileName(string apiName, bool isSplitAPI, bool isInitialAPI)
3336
{
3437
// in case the api name has been appended with ;rev={revisionNumber}, take only the api name initially provided by the user in the creator config
3538
string sanitizedAPIName = GenerateOriginalAPIName(apiName);
39+
3640
if (isSplitAPI == true)
3741
{
38-
return isInitialAPI == true ? $@"/{apimServiceName}-{sanitizedAPIName}-initial.api.template.json" : $@"/{apimServiceName}-{sanitizedAPIName}-subsequent.api.template.json";
42+
return isInitialAPI == true ? $@"/{sanitizedAPIName}-initial.api.template.json" : $@"/{sanitizedAPIName}-subsequent.api.template.json";
3943
}
4044
else
4145
{
42-
return $@"/{apimServiceName}-{sanitizedAPIName}.api.template.json";
46+
return $@"/{sanitizedAPIName}.api.template.json";
4347
}
4448
}
4549

4650
public string GenerateExtractorAPIFileName(string singleAPIName, string baseFileName)
4751
{
48-
return singleAPIName == null ? $@"/{baseFileName}-apis.template.json" : $@"/{baseFileName}-{singleAPIName}-api.template.json";
52+
if (baseFileName.Length > 0)
53+
baseFileName += "-";
54+
55+
return singleAPIName == null ? $@"/{baseFileName}apis.template.json" : $@"/{baseFileName}{singleAPIName}-api.template.json";
4956
}
5057

5158
public string GenerateOriginalAPIName(string apiName)

src/APIM_ARMTemplate/apimtemplate/Creator/TemplateCreators/MasterTemplateCreator.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ public Template CreateLinkedMasterTemplate(CreatorConfig creatorConfig,
8686
string initialAPIDeploymentResourceName = $"{originalAPIName}-InitialAPITemplate";
8787
string subsequentAPIDeploymentResourceName = $"{originalAPIName}-SubsequentAPITemplate";
8888

89-
string initialAPIFileName = fileNameGenerator.GenerateCreatorAPIFileName(apiInfo.name, apiInfo.isSplit, true, apimServiceName);
89+
string initialAPIFileName = fileNameGenerator.GenerateCreatorAPIFileName(apiInfo.name, apiInfo.isSplit, true);
9090
string initialAPIUri = GenerateLinkedTemplateUri(creatorConfig, initialAPIFileName);
9191
string[] initialAPIDependsOn = CreateAPIResourceDependencies(globalServicePolicyTemplate, apiVersionSetTemplate, productsTemplate, loggersTemplate, backendsTemplate, authorizationServersTemplate, tagTemplate, apiInfo);
9292
resources.Add(this.CreateLinkedMasterTemplateResource(initialAPIDeploymentResourceName, initialAPIUri, initialAPIDependsOn));
9393

94-
string subsequentAPIFileName = fileNameGenerator.GenerateCreatorAPIFileName(apiInfo.name, apiInfo.isSplit, false, apimServiceName);
94+
string subsequentAPIFileName = fileNameGenerator.GenerateCreatorAPIFileName(apiInfo.name, apiInfo.isSplit, false);
9595
string subsequentAPIUri = GenerateLinkedTemplateUri(creatorConfig, subsequentAPIFileName);
9696
string[] subsequentAPIDependsOn = new string[] { $"[resourceId('Microsoft.Resources/deployments', '{initialAPIDeploymentResourceName}')]" };
9797
resources.Add(this.CreateLinkedMasterTemplateResource(subsequentAPIDeploymentResourceName, subsequentAPIUri, subsequentAPIDependsOn));
@@ -101,7 +101,7 @@ public Template CreateLinkedMasterTemplate(CreatorConfig creatorConfig,
101101
// add a deployment resource for the unified api template file
102102
string originalAPIName = fileNameGenerator.GenerateOriginalAPIName(apiInfo.name);
103103
string unifiedAPIDeploymentResourceName = $"{originalAPIName}-APITemplate";
104-
string unifiedAPIFileName = fileNameGenerator.GenerateCreatorAPIFileName(apiInfo.name, apiInfo.isSplit, true, apimServiceName);
104+
string unifiedAPIFileName = fileNameGenerator.GenerateCreatorAPIFileName(apiInfo.name, apiInfo.isSplit, true);
105105
string unifiedAPIUri = GenerateLinkedTemplateUri(creatorConfig, unifiedAPIFileName);
106106
string[] unifiedAPIDependsOn = CreateAPIResourceDependencies(globalServicePolicyTemplate, apiVersionSetTemplate, productsTemplate, loggersTemplate, backendsTemplate, authorizationServersTemplate, tagTemplate, apiInfo);
107107
resources.Add(this.CreateLinkedMasterTemplateResource(unifiedAPIDeploymentResourceName, unifiedAPIUri, unifiedAPIDependsOn));

0 commit comments

Comments
 (0)