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

Commit 945ebae

Browse files
authored
Merge pull request #174 from Azure/lucashh-hotfix
fix validation null ref error
2 parents 6036a90 + e679148 commit 945ebae

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

src/APIM_ARMTemplate/apimtemplate/Creator/Utilities/CreatorConfigurationValidator.cs

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,15 @@ public bool ValidateCreatorConfig(CreatorConfig creatorConfig)
5151
public bool ValidateProducts(CreatorConfig creatorConfig)
5252
{
5353
bool isValid = true;
54-
foreach(ProductsTemplateProperties product in creatorConfig.products)
54+
if (creatorConfig.products != null)
5555
{
56-
if (product.displayName == null)
56+
foreach (ProductsTemplateProperties product in creatorConfig.products)
5757
{
58-
isValid = false;
59-
throw new CommandParsingException(commandLineApplication, "Display name is required if an Product is provided");
58+
if (product.displayName == null)
59+
{
60+
isValid = false;
61+
throw new CommandParsingException(commandLineApplication, "Display name is required if an Product is provided");
62+
}
6063
}
6164
}
6265
return isValid;
@@ -65,12 +68,15 @@ public bool ValidateProducts(CreatorConfig creatorConfig)
6568
public bool ValidateLoggers(CreatorConfig creatorConfig)
6669
{
6770
bool isValid = true;
68-
foreach (LoggerConfig logger in creatorConfig.loggers)
71+
if (creatorConfig.loggers != null)
6972
{
70-
if (logger.name == null)
73+
foreach (LoggerConfig logger in creatorConfig.loggers)
7174
{
72-
isValid = false;
73-
throw new CommandParsingException(commandLineApplication, "Name is required if an Logger is provided");
75+
if (logger.name == null)
76+
{
77+
isValid = false;
78+
throw new CommandParsingException(commandLineApplication, "Name is required if an Logger is provided");
79+
}
7480
}
7581
}
7682
return isValid;
@@ -79,12 +85,15 @@ public bool ValidateLoggers(CreatorConfig creatorConfig)
7985
public bool ValidateBackends(CreatorConfig creatorConfig)
8086
{
8187
bool isValid = true;
82-
foreach (BackendTemplateProperties backend in creatorConfig.backends)
88+
if (creatorConfig.backends != null)
8389
{
84-
if (backend.title == null)
90+
foreach (BackendTemplateProperties backend in creatorConfig.backends)
8591
{
86-
isValid = false;
87-
throw new CommandParsingException(commandLineApplication, "Title is required if a Backend is provided");
92+
if (backend.title == null)
93+
{
94+
isValid = false;
95+
throw new CommandParsingException(commandLineApplication, "Title is required if a Backend is provided");
96+
}
8897
}
8998
}
9099
return isValid;
@@ -93,12 +102,15 @@ public bool ValidateBackends(CreatorConfig creatorConfig)
93102
public bool ValidateAuthorizationServers(CreatorConfig creatorConfig)
94103
{
95104
bool isValid = true;
96-
foreach (AuthorizationServerTemplateProperties authorizationServer in creatorConfig.authorizationServers)
105+
if (creatorConfig.authorizationServers != null)
97106
{
98-
if (authorizationServer.displayName == null)
107+
foreach (AuthorizationServerTemplateProperties authorizationServer in creatorConfig.authorizationServers)
99108
{
100-
isValid = false;
101-
throw new CommandParsingException(commandLineApplication, "Display name is required if an Authorization Server is provided");
109+
if (authorizationServer.displayName == null)
110+
{
111+
isValid = false;
112+
throw new CommandParsingException(commandLineApplication, "Display name is required if an Authorization Server is provided");
113+
}
102114
}
103115
}
104116
return isValid;
@@ -178,12 +190,15 @@ public bool ValidateAPIs(CreatorConfig creatorConfig)
178190
public bool ValidateAPIVersionSets(CreatorConfig creatorConfig)
179191
{
180192
bool isValid = true;
181-
foreach (APIVersionSetConfig apiVersionSet in creatorConfig.apiVersionSets)
193+
if(creatorConfig.apiVersionSets != null)
182194
{
183-
if (apiVersionSet != null && apiVersionSet.displayName == null)
195+
foreach (APIVersionSetConfig apiVersionSet in creatorConfig.apiVersionSets)
184196
{
185-
isValid = false;
186-
throw new CommandParsingException(commandLineApplication, "Display name is required if an API Version Set is provided");
197+
if (apiVersionSet != null && apiVersionSet.displayName == null)
198+
{
199+
isValid = false;
200+
throw new CommandParsingException(commandLineApplication, "Display name is required if an API Version Set is provided");
201+
}
187202
}
188203
}
189204
return isValid;

0 commit comments

Comments
 (0)