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
22 changes: 14 additions & 8 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"cSpell.words": [
"CSDL",
"Edmx",
"intune",
"Markdig",
"Mooncake",
"olders"
]
"cSpell.words": [
"CSDL",
"Edmx",
"intune",
"Markdig",
"Mooncake",
"olders"
],
"json.schemas": [
{
"fileMatch": ["cloud-exclusions.json"],
"url": "./schema/cloud.exclusions.schema.json"
}
]
}
28 changes: 0 additions & 28 deletions CheckCloudSupport.sln

This file was deleted.

8 changes: 8 additions & 0 deletions CheckCloudSupport.slnx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Solution>
<Folder Name="/src/">
<Project Path="src/CheckCloudSupport.csproj" />
</Folder>
<Folder Name="/test/">
<Project Path="test/CheckCloudSupportTests.csproj" />
</Folder>
</Solution>
18 changes: 16 additions & 2 deletions schema/cloud.exclusions.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
"description": "The HTTP method for the API to exclude.",
"type": "string"
},
"fileName": {
"description": "The API doc file name. Setting this property excludes all APIs in the specified file from the specified cloud.",
"type": "string"
},
"cloud": {
"description": "The cloud to exclude this API from. Must be 'Global', 'UsGov', or 'China'.",
"type": "string",
Expand All @@ -22,13 +26,23 @@
"UsGov",
"China"
]
},
"description": {
"description": "A description of the reason for the exclusion.",
"type": "string"
}
},
"required": [
"apiPath",
"operation",
"cloud"
],
"oneOf": [
{
"required": ["apiPath", "operation"]
},
{
"required": ["fileName"]
}
],
"additionalProperties": false
}
},
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="0.45.0" />
<PackageReference Include="Markdig" Version="1.1.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.3" />
<PackageReference Include="Microsoft.OpenApi" Version="3.4.0" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="3.1.0" />
Expand Down
20 changes: 14 additions & 6 deletions src/Extensions/OpenApiUrlTreeNodeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,27 +99,35 @@ public static class OpenApiUrlTreeNodeExtensions
/// </summary>
/// <param name="node">The API URL node to check.</param>
/// <param name="method">The HTTP method to check for.</param>
/// <param name="filePath">The API document file path.</param>
/// <returns>The <see cref="CloudSupportStatus"/> indicating the cloud support status of the API.</returns>
public static CloudSupportStatus GetCloudSupportStatus(this OpenApiUrlTreeNode node, HttpMethod? method)
public static CloudSupportStatus GetCloudSupportStatus(
this OpenApiUrlTreeNode node,
HttpMethod? method,
string filePath)
{
if (method == null)
{
return CloudSupportStatus.Unknown;
}

var fileName = Path.GetFileName(filePath);

if (node.Path.EndsWith("\\bundles\\{driveItem-id}"))
{
method = HttpMethod.Get;
}
{
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.CheckIfCloudExcluded(node.Path, method, "UsGov") &&
!OpenAPIOverrides.CheckIfCloudExcludedForFile(fileName, "UsGov");
var supportsChina = node.PathItems.ContainsKey("China") &&
(node.PathItems["China"].Operations?.ContainsKey(method) ?? false) &&
!OpenAPIOverrides.CheckIfCloudExcluded(node.Path, method, "China");
!OpenAPIOverrides.CheckIfCloudExcluded(node.Path, method, "China") &&
!OpenAPIOverrides.CheckIfCloudExcludedForFile(fileName, "China");

if (!supportsGlobal)
{
Expand Down
7 changes: 7 additions & 0 deletions src/OpenAPI/CloudExclusion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ public class CloudExclusion
[JsonPropertyName("operation")]
public string? Operation { get; set; }

/// <summary>
/// Gets or sets the API doc file name. Setting this property excludes
/// all APIs in the specified file from the specified cloud.
/// </summary>
[JsonPropertyName("fileName")]
public string? FileName { get; set; }

/// <summary>
/// Gets or sets the cloud to exclude.
/// </summary>
Expand Down
13 changes: 13 additions & 0 deletions src/OpenAPI/OpenAPIOverrides.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ public static bool CheckIfCloudExcluded(string apiPath, HttpMethod? method, stri
string.Compare(e.Cloud, cloud, StringComparison.InvariantCultureIgnoreCase) == 0) ?? false;
}

/// <summary>
/// Checks if a cloud is excluded for a given API doc file. This is used to exclude entire
/// files of APIs that don't function in certain clouds, even if the individual API paths aren't known.
/// </summary>
/// <param name="fileName">The name of the API doc file to check for an exclusion for.</param>
/// <param name="cloud">The cloud to check.</param>
/// <returns>True if the given cloud is excluded for the specified file.</returns>
public static bool CheckIfCloudExcludedForFile(string fileName, string cloud)
{
return cloudExclusions?.Any(e => string.Compare(e.FileName, fileName, StringComparison.InvariantCultureIgnoreCase) == 0 &&
string.Compare(e.Cloud, cloud, StringComparison.InvariantCultureIgnoreCase) == 0) ?? false;
}

private static void LoadOverridesFromJson(string? jsonFile)
{
if (!string.IsNullOrEmpty(jsonFile))
Expand Down
6 changes: 3 additions & 3 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@
continue;
}

var supportStatus = operationNode.GetCloudSupportStatus(operation.Method);
var supportStatus = operationNode.GetCloudSupportStatus(operation.Method, apiDoc.FilePath);
OutputLogger.Logger?.LogInformation("{path} support status: {status}", operation.Path, supportStatus);
if (supportStatus != CloudSupportStatus.Unknown &&
apiDoc.CloudSupportStatus != CloudSupportStatus.Unknown &&
Expand Down Expand Up @@ -327,7 +327,7 @@
continue;
}

var supportStatus = operationNode.GetCloudSupportStatus(operation.Method);
var supportStatus = operationNode.GetCloudSupportStatus(operation.Method, apiDoc.FilePath);
OutputLogger.Logger?.LogInformation("{version} {path} support status: {status}", "v1", operation.Path, supportStatus);
if (supportStatus != CloudSupportStatus.Unknown &&
v1CloudSupportStatus != CloudSupportStatus.Unknown &&
Expand Down Expand Up @@ -364,7 +364,7 @@
continue;
}

var supportStatus = operationNode.GetCloudSupportStatus(operation.Method);
var supportStatus = operationNode.GetCloudSupportStatus(operation.Method, apiDoc.FilePath);
OutputLogger.Logger?.LogInformation("{version} {path} support status: {status}", "beta", operation.Path, supportStatus);
if (supportStatus != CloudSupportStatus.Unknown &&
betaCloudSupportStatus != CloudSupportStatus.Unknown &&
Expand Down
2 changes: 1 addition & 1 deletion test/CheckCloudSupportTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.4">
<PackageReference Include="coverlet.collector" Version="8.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
Expand Down