Skip to content

Commit a8945aa

Browse files
committed
Relax property validation for ApplicationPackage JSON
Commented out the exception for missing properties in ApplicationPackage JSON validation due to the TargetPlatform property being omitted for packages marked for deletion. Now, only extra properties will trigger an exception, allowing processing to continue when required properties are missing for deletable packages. Also, always validates JSON structure regardless of fileStatus.
1 parent f30a461 commit a8945aa

File tree

1 file changed

+11
-25
lines changed
  • AppControl Manager/eXclude/PartnerCenter

1 file changed

+11
-25
lines changed

AppControl Manager/eXclude/PartnerCenter/Program.cs

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -127,44 +127,30 @@ internal static void ValidateJsonStructure(JsonElement jsonElement)
127127
HashSet<string> extraProperties = new(actualProperties);
128128
extraProperties.ExceptWith(expectedProperties);
129129

130+
// TargetPlatform property disappears from all packages once we mark the oldest package for deletion!
131+
// So commenting this check because it would just always throw and wouldn't let us continue.
132+
130133
// Throw exceptions if there are discrepancies, shouldn't continue.
131-
if (missingProperties.Count > 0)
132-
{
133-
throw new InvalidOperationException($"Missing required properties in ApplicationPackage JSON: {string.Join(", ", missingProperties)}");
134-
}
134+
// if (missingProperties.Count > 0)
135+
// {
136+
// throw new InvalidOperationException($"Missing required properties in ApplicationPackage JSON: {string.Join(", ", missingProperties)}");
137+
// }
135138

139+
// Throwing on extra properties is good to keep because that means we need to update the JSON class for source-generated (de)serialization.
136140
if (extraProperties.Count > 0)
137141
{
138142
throw new InvalidOperationException($"Unexpected extra properties in ApplicationPackage JSON: {string.Join(", ", extraProperties)}. This may indicate new features have been added to the API that are not supported by this version of the code.");
139143
}
140144
}
141145

142146
/// <summary>
143-
/// Validates an ApplicationPackage.
147+
/// An ApplicationPackage from JsonElement with validation.
144148
/// </summary>
145-
/// <param name="jsonElement"></param>
146-
/// <returns>An ApplicationPackage from JsonElement with validation.</returns>
147-
/// <exception cref="InvalidOperationException"></exception>
148149
internal static ApplicationPackage FromJsonElement(JsonElement jsonElement)
149150
{
150-
string? fileStatus = null;
151-
if (jsonElement.TryGetProperty("fileStatus", out JsonElement statusElement))
152-
{
153-
fileStatus = statusElement.GetString();
154-
}
155-
156-
// Only perform strict validation if not PendingDelete
157-
if (!string.Equals(fileStatus, "PendingDelete", StringComparison.OrdinalIgnoreCase))
158-
{
159-
ValidateJsonStructure(jsonElement);
160-
}
161-
// else: Skip validation intentionally for PendingDelete packages to avoid false failures when the API omits properties (e.g., targetPlatform) for those entries.
162-
// We don't need to validate them anyway since we're getting rid of them.
163-
164-
ApplicationPackage? package = JsonSerializer.Deserialize(
165-
jsonElement.GetRawText(),
166-
ApplicationPackageJsonContext.Default.ApplicationPackage);
151+
ValidateJsonStructure(jsonElement);
167152

153+
ApplicationPackage? package = JsonSerializer.Deserialize(jsonElement.GetRawText(), ApplicationPackageJsonContext.Default.ApplicationPackage);
168154
return package ?? throw new InvalidOperationException("Failed to deserialize ApplicationPackage");
169155
}
170156
}

0 commit comments

Comments
 (0)