Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions schema/cloud.exclusions.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
"enum": [
"Global",
"UsGov",
"UsGovL4",
"UsGovL5",
"China"
]
},
Expand Down
2 changes: 1 addition & 1 deletion src/CheckCloudSupport.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Markdig" Version="1.1.3" />
<PackageReference Include="Markdig" Version="1.2.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.7" />
<PackageReference Include="Microsoft.OpenApi" Version="3.5.3" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="3.2.1" />
Expand Down
8 changes: 6 additions & 2 deletions src/Docs/ApiDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,13 @@ private static string GetIncludeLine(CloudSupportStatus status, string includeDi
return status switch
{
CloudSupportStatus.AllClouds => $"[!INCLUDE [national-cloud-support]({includeDirectory}/all-clouds.md)]",
CloudSupportStatus.GlobalAndUSGov => $"[!INCLUDE [national-cloud-support]({includeDirectory}/global-us.md)]",
CloudSupportStatus.GlobalAndChina => $"[!INCLUDE [national-cloud-support]({includeDirectory}/global-china.md)]",
CloudSupportStatus.GlobalOnly => $"[!INCLUDE [national-cloud-support]({includeDirectory}/global-only.md)]",
CloudSupportStatus.GlobalAndChinaAndUsGovL4 => $"[!INCLUDE [national-cloud-support]({includeDirectory}/global-china-us-l4.md)]",
CloudSupportStatus.GlobalAndChinaAndUsGovL5 => $"[!INCLUDE [national-cloud-support]({includeDirectory}/global-china-us-l5.md)]",
CloudSupportStatus.GlobalAndUSGov => $"[!INCLUDE [national-cloud-support]({includeDirectory}/global-us.md)]",
CloudSupportStatus.GlobalAndUsGovL4 => $"[!INCLUDE [national-cloud-support]({includeDirectory}/global-us-l4.md)]",
CloudSupportStatus.GlobalAndUsGovL5 => $"[!INCLUDE [national-cloud-support]({includeDirectory}/global-us-l5.md)]",
CloudSupportStatus.Global => $"[!INCLUDE [national-cloud-support]({includeDirectory}/global-only.md)]",
_ => throw new ArgumentException("Invalid cloud support status"),
};
}
Expand Down
59 changes: 50 additions & 9 deletions src/Docs/CloudSupportStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,71 @@ namespace CheckCloudSupport.Docs;
/// <summary>
/// Represents the cloud support status of an API.
/// </summary>
[Flags]
public enum CloudSupportStatus
{
/// <summary>
/// Cloud support status is undetermined.
/// </summary>
Unknown,
Unknown = 0,

/// <summary>
/// API is supported in all public national clouds.
/// API is supported in Chinese cloud.
/// </summary>
AllClouds,
China = 1 << 0,

/// <summary>
/// API is supported in the global and US Government clouds only.
/// API is supported in the global cloud.
/// </summary>
GlobalAndUSGov,
Global = 1 << 1,

/// <summary>
/// API is supported in the global and Chinese clouds only.
/// API is supported in the US Government L4 cloud.
/// </summary>
GlobalAndChina,
USGovL4 = 1 << 2,

/// <summary>
/// API is supported in the global cloud only.
/// API is supported in the US Government L5 cloud.
/// </summary>
GlobalOnly,
USGovL5 = 1 << 3,

/// <summary>
/// API is supported in the US Government cloud (L4 and L5).
/// </summary>
USGov = USGovL4 | USGovL5,

/// <summary>
/// API is supported in all clouds (China, Global, and US Government).
/// </summary>
AllClouds = China | Global | USGov,

/// <summary>
/// API is supported in both Global and US Government clouds.
/// </summary>
GlobalAndUSGov = Global | USGov,

/// <summary>
/// API is supported in both Global and Chinese clouds.
/// </summary>
GlobalAndChina = Global | China,

/// <summary>
/// API is supported in both Global and US Government L4 clouds.
/// </summary>
GlobalAndUsGovL4 = Global | USGovL4,

/// <summary>
/// API is supported in both Global and US Government L5 clouds.
/// </summary>
GlobalAndUsGovL5 = Global | USGovL5,

/// <summary>
/// API is supported in Global, Chinese, and US Government L4 clouds.
/// </summary>
GlobalAndChinaAndUsGovL4 = Global | China | USGovL4,

/// <summary>
/// API is supported in Global, Chinese, and US Government L5 clouds.
/// </summary>
GlobalAndChinaAndUsGovL5 = Global | China | USGovL5,
}
26 changes: 0 additions & 26 deletions src/Docs/DocSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,32 +38,6 @@ public static async Task<DocSet> CreateFromDirectory(string docsRoot)
return docSet;
}

/// <summary>
/// Combines two <see cref="CloudSupportStatus"/> into the most inclusive value.
/// </summary>
/// <param name="a">The first status.</param>
/// <param name="b">The second status.</param>
/// <returns>The combined status.</returns>
public static CloudSupportStatus CombineStatuses(CloudSupportStatus a, CloudSupportStatus b)
{
if (a == b)
{
return a;
}

if (a == CloudSupportStatus.Unknown || a == CloudSupportStatus.GlobalOnly)
{
return b == CloudSupportStatus.Unknown ? CloudSupportStatus.GlobalOnly : b;
}

if (b == CloudSupportStatus.Unknown || b == CloudSupportStatus.GlobalOnly)
{
return a;
}

return CloudSupportStatus.AllClouds;
}

/// <summary>
/// Loads the Markdown files in the root directory into the <see cref="DocSet"/>.
/// </summary>
Expand Down
56 changes: 40 additions & 16 deletions src/Extensions/OpenApiUrlTreeNodeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,33 +118,57 @@ public static CloudSupportStatus GetCloudSupportStatus(
method = HttpMethod.Get;
}

var supportsGlobal = node.PathItems.ContainsKey("Global") &&
(node.PathItems["Global"].Operations?.ContainsKey(method) ?? false);
var supportsUsGov = node.PathItems.ContainsKey("UsGov") &&
(node.PathItems["UsGov"].Operations?.ContainsKey(method) ?? false) &&
!OpenAPIOverrides.CheckIfCloudExcluded(node.Path, method, "UsGov") &&
!OpenAPIOverrides.CheckIfCloudExcludedForFile(fileName, "UsGov");
var supportsChina = node.PathItems.ContainsKey("China") &&
(node.PathItems["China"].Operations?.ContainsKey(method) ?? false) &&
var supportStatus = node.PathItems.TryGetValue("Global", out IOpenApiPathItem? globalValue) &&
(globalValue.Operations?.ContainsKey(method) ?? false)
? CloudSupportStatus.Global
: CloudSupportStatus.Unknown;
if (supportStatus == CloudSupportStatus.Unknown)
{
return supportStatus;
}

if (node.PathItems.TryGetValue("UsGov", out IOpenApiPathItem? usGovValue) &&
(usGovValue.Operations?.ContainsKey(method) ?? false))
{
supportStatus |= GetUsGovCloudSupportStatus(node.Path, method, fileName);
}

if (node.PathItems.TryGetValue("China", out IOpenApiPathItem? chinaValue) &&
(chinaValue.Operations?.ContainsKey(method) ?? false) &&
!OpenAPIOverrides.CheckIfCloudExcluded(node.Path, method, "China") &&
!OpenAPIOverrides.CheckIfCloudExcludedForFile(fileName, "China");
!OpenAPIOverrides.CheckIfCloudExcludedForFile(fileName, "China"))
{
supportStatus |= CloudSupportStatus.China;
}

return supportStatus;
}

private static CloudSupportStatus GetUsGovCloudSupportStatus(
string apiPath,
HttpMethod? method,
string fileName)
{
var supportStatus = CloudSupportStatus.USGov;

if (!supportsGlobal)
if (OpenAPIOverrides.CheckIfCloudExcluded(apiPath, method, "UsGov") ||
OpenAPIOverrides.CheckIfCloudExcludedForFile(fileName, "UsGov"))
{
// Only process APIs that exist in Global cloud
return CloudSupportStatus.Unknown;
}

if (supportsUsGov && supportsChina)
if (OpenAPIOverrides.CheckIfCloudExcluded(apiPath, method, "UsGovL4") ||
OpenAPIOverrides.CheckIfCloudExcludedForFile(fileName, "UsGovL4"))
{
return CloudSupportStatus.AllClouds;
supportStatus &= ~CloudSupportStatus.USGovL4;
}

if (!supportsUsGov && !supportsChina)
if (OpenAPIOverrides.CheckIfCloudExcluded(apiPath, method, "UsGovL5") ||
OpenAPIOverrides.CheckIfCloudExcludedForFile(fileName, "UsGovL5"))
{
return CloudSupportStatus.GlobalOnly;
supportStatus &= ~CloudSupportStatus.USGovL5;
}

return supportsUsGov ? CloudSupportStatus.GlobalAndUSGov : CloudSupportStatus.GlobalAndChina;
return supportStatus;
}
}
8 changes: 4 additions & 4 deletions src/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static string NormalizeIdSegments(this string path)
normalizedPath = normalizedPath.Replace("/{name}", "/{id}");

// Replace any segments wrapped in braces that contain "id"
normalizedPath = IdSegmentRegex().Replace(normalizedPath, "{id}");
normalizedPath = IdSegmentRegex().Replace(normalizedPath, "/{id}");

return normalizedPath;
}
Expand Down Expand Up @@ -211,13 +211,13 @@ public static bool IsEqualIgnoringCase(this string value, string compareTo)
return compareValue == 0;
}

[GeneratedRegex("{[^{}]*id[^{}]*}", RegexOptions.IgnoreCase)]
[GeneratedRegex("\\/{[^{}]*id[^{}]*}", RegexOptions.IgnoreCase)]
private static partial Regex IdSegmentRegex();

[GeneratedRegex("\\(((?>\\w*='?\\{?[\\w-]*\\}?'?,?)+)\\)")]
[GeneratedRegex("\\(((?>\\w*='?\\{?[\\w@-]*\\}?'?,?)+)\\)")]
private static partial Regex ParameterListRegex();

[GeneratedRegex("(?<param>\\w*)='?(?<value>\\{?[\\w-]*\\}?)'?")]
[GeneratedRegex("(?<param>\\w*)='?(?<value>\\{?[\\w@-]*\\}?)'?")]
private static partial Regex ParameterValuePairRegex();

[GeneratedRegex("^\\/users\\/{id}\\/drive\\/")]
Expand Down
6 changes: 3 additions & 3 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@
supportStatus,
apiDoc.CloudSupportStatus);

apiDoc.CloudSupportStatus = DocSet.CombineStatuses(apiDoc.CloudSupportStatus, supportStatus);
apiDoc.CloudSupportStatus |= supportStatus;
}
else
{
Expand Down Expand Up @@ -340,7 +340,7 @@
supportStatus,
v1CloudSupportStatus);

v1CloudSupportStatus = DocSet.CombineStatuses(v1CloudSupportStatus, supportStatus);
v1CloudSupportStatus |= supportStatus;
}
else
{
Expand Down Expand Up @@ -377,7 +377,7 @@
supportStatus,
betaCloudSupportStatus);

betaCloudSupportStatus = DocSet.CombineStatuses(betaCloudSupportStatus, supportStatus);
betaCloudSupportStatus |= supportStatus;
}
else
{
Expand Down
47 changes: 0 additions & 47 deletions test/DocSetTests.cs

This file was deleted.