Skip to content

Commit 3cf5c75

Browse files
committed
Null check
1 parent 2a72c87 commit 3cf5c75

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/core/EdFi.DataManagementService.Core/ApiService.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -290,12 +290,18 @@ public JsonArray GetDependencies()
290290
foreach (JsonNode projectSchemaNode in projectSchemaNodes)
291291
{
292292

293-
var resourceSchemasObj = projectSchemaNode["resourceSchemas"]!.AsObject().Select(x => new ResourceSchema(x.Value!));
293+
var resourceSchemas = projectSchemaNode["resourceSchemas"]?.AsObject().Select(x => new ResourceSchema(x.Value!)).ToList();
294+
if (resourceSchemas == null)
295+
{
296+
string errorMessage = "No resourceSchemas found, ApiSchema.json is invalid";
297+
_logger.LogCritical(errorMessage);
298+
throw new InvalidOperationException(errorMessage);
299+
}
294300

295301
Dictionary<string, List<string>> dependencies =
296-
resourceSchemasObj!.ToDictionary(rs => rs.ResourceName.Value, rs => new List<string>());
302+
resourceSchemas.ToDictionary(rs => rs.ResourceName.Value, rs => new List<string>());
297303

298-
foreach (var resourceSchema in resourceSchemasObj)
304+
foreach (var resourceSchema in resourceSchemas)
299305
{
300306
foreach (var documentPath in resourceSchema.DocumentPaths.Where(d => d.IsReference))
301307
{
@@ -317,7 +323,7 @@ public JsonArray GetDependencies()
317323

318324
int RecursivelyDetermineDependencies(string resourceName, int depth)
319325
{
320-
326+
// Code Smell here:
321327
// These resources are similar to abstract base classes, so they are not represented in the resourceSchemas
322328
// portion of the schema document. This is a rudimentary replacement with the most specific version of the resource
323329
if (resourceName == "EducationOrganization")

0 commit comments

Comments
 (0)