Skip to content

Commit 2bcafdf

Browse files
committed
Refactor JSON value type checks to use GetValueKind for consistency
1 parent 368a2d9 commit 2bcafdf

File tree

12 files changed

+30
-21
lines changed

12 files changed

+30
-21
lines changed

src/Confix.Tool/src/Confix.Library/Entities/Component/Configuration/ComponentReferenceConfiguration.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Text.Json;
12
using System.Text.Json.Nodes;
23
using Confix.Utilities.Json;
34
using Confix.Utilities.Parsing;
@@ -48,7 +49,7 @@ public static ComponentReferenceConfiguration Parse(string key, JsonNode node)
4849
"The component key must be in the format '@provider/componentName'.");
4950
}
5051

51-
if (node.GetSchemaValueType() is SchemaValueType.String)
52+
if (node.GetValueKind() is JsonValueKind.String)
5253
{
5354
return new ComponentReferenceConfiguration(
5455
provider,
@@ -58,7 +59,7 @@ public static ComponentReferenceConfiguration Parse(string key, JsonNode node)
5859
null);
5960
}
6061

61-
if (node.GetSchemaValueType() is SchemaValueType.Boolean)
62+
if (node.GetValueKind() is JsonValueKind.True)
6263
{
6364
return new ComponentReferenceConfiguration(
6465
provider,
@@ -76,7 +77,7 @@ public static ComponentReferenceConfiguration Parse(string key, JsonNode node)
7677

7778
var mountingPoints =
7879
obj.TryGetNonNullPropertyValue(FieldNames.MountingPoint, out var mountingPointNode)
79-
? mountingPointNode.GetSchemaValueType() is SchemaValueType.Array
80+
? mountingPointNode.GetValueKind() is JsonValueKind.Array
8081
? mountingPointNode
8182
.ExpectArray()
8283
.WhereNotNull()

src/Confix.Tool/src/Confix.Library/Entities/Environment/Configuration/EnvironmentConfiguration.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Text.Json;
12
using System.Text.Json.Nodes;
23
using Confix.Utilities.Json;
34
using Json.Schema;
@@ -25,7 +26,7 @@ public EnvironmentConfiguration(
2526

2627
public static EnvironmentConfiguration Parse(JsonNode node)
2728
{
28-
if (node.GetSchemaValueType() is SchemaValueType.String)
29+
if (node.GetValueKind() is JsonValueKind.String)
2930
{
3031
return new EnvironmentConfiguration(node.ExpectValue<string>(), null);
3132
}

src/Confix.Tool/src/Confix.Library/Entities/Project/Configuration/ConfigurationFileConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public ConfigurationFileConfiguration(string? type, JsonNode value)
2424

2525
public static ConfigurationFileConfiguration Parse(JsonNode node)
2626
{
27-
if (node.GetSchemaValueType() is SchemaValueType.String)
27+
if (node.GetValueKind() is JsonValueKind.String)
2828
{
2929
// TODO const?
3030
return new ConfigurationFileConfiguration("inline", node);

src/Confix.Tool/src/Confix.Library/Middlewares/LoadConfiguration/MagicPathRewriter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Text.Json;
12
using System.Text.Json.Nodes;
23
using Confix.Tool.Commands.Logging;
34
using Confix.Tool.Schema;
@@ -18,9 +19,9 @@ public sealed class MagicPathRewriter : JsonDocumentRewriter<MagicPathContext>
1819
{
1920
protected override JsonNode Rewrite(JsonValue value, MagicPathContext context)
2021
{
21-
switch (value.GetSchemaValueType())
22+
switch (value.GetValueKind())
2223
{
23-
case SchemaValueType.String when MagicPath.From(value) is { } magicPath:
24+
case JsonValueKind.String when MagicPath.From(value) is { } magicPath:
2425
var replacedValue = magicPath.Replace(context);
2526

2627
App.Log.ReplacedMagicPath((string?) value, replacedValue);

src/Confix.Tool/src/Confix.Library/Pipelines/Reporting/Dependency/Regex/RegexDependencyProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Text.Json;
12
using System.Text.Json.Nodes;
23
using System.Text.RegularExpressions;
34
using Json.More;
@@ -30,7 +31,7 @@ public RegexDependencyProvider(RegexDependencyProviderDefinition definition)
3031

3132
public void Analyze(DependencyAnalyzerContext context, JsonNode node)
3233
{
33-
if (node.GetSchemaValueType() is not SchemaValueType.String)
34+
if (node.GetValueKind() is not JsonValueKind.String)
3435
{
3536
return;
3637
}

src/Confix.Tool/src/Confix.Library/Pipelines/Reporting/Dependency/ReportingDependencyConfiguration.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Text.Json;
12
using System.Text.Json.Nodes;
23
using Confix.Utilities.Json;
34
using Json.Schema;
@@ -60,7 +61,7 @@ file static class Extensions
6061

6162
if (!configuration.Configuration.TryGetPropertyValue("Kind", out var kind) ||
6263
kind is not JsonValue value ||
63-
value.GetSchemaValueType() is not SchemaValueType.String)
64+
value.GetValueKind() is not JsonValueKind.String)
6465
{
6566
return null;
6667
}

src/Confix.Tool/src/Confix.Library/Utilities/Json/JsonNodeExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public static bool TryGetNonNullPropertyValue(
4343
(_, JsonValue nodeValue) => nodeValue,
4444
_ => throw new InvalidOperationException($"""
4545
Cannot merge nodes of different types:
46-
Source: {source.GetSchemaValueType()}
47-
Node: {node.GetSchemaValueType()}
46+
Source: {source.GetValueKind()}
47+
Node: {node.GetValueKind()}
4848
""")
4949
};
5050

src/Confix.Tool/src/Confix.Library/Utilities/Json/PrefixJsonNamesRewriter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Text.Json;
12
using System.Text.Json.Nodes;
23
using Json.More;
34
using Json.Schema;
@@ -28,7 +29,7 @@ protected override JsonNode Rewrite(JsonObject obj, PrefixJsonNamesContext conte
2829

2930
if (field is RefKeyword.Name &&
3031
value is JsonValue refValue &&
31-
refValue.GetSchemaValueType() is SchemaValueType.String)
32+
refValue.GetValueKind() is JsonValueKind.String)
3233
{
3334
var parts = refValue.GetValue<object>().ToString()!.Split("/");
3435
parts[^1] = $"{prefix}{parts[^1]}";

src/Confix.Tool/src/Confix.Library/Variables/JsonVariableRewriter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ namespace Confix.Variables;
1010
public sealed class JsonVariableRewriter : JsonDocumentRewriter<JsonVariableRewriterContext>
1111
{
1212
protected override JsonNode Rewrite(JsonValue value, JsonVariableRewriterContext context)
13-
=> value.GetSchemaValueType() switch
13+
=> value.GetValueKind() switch
1414
{
15-
SchemaValueType.String => RewriteVariable((string) value!, context),
15+
JsonValueKind.String => RewriteVariable((string) value!, context),
1616
_ => value.Deserialize<JsonNode>()!
1717
};
1818

src/Confix.Tool/src/Confix.Library/Variables/Providers/AzureKeyVault/AzureKeyVaultProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Text.Json;
12
using System.Text.Json.Nodes;
23
using Azure.Identity;
34
using Azure.Security.KeyVault.Secrets;
@@ -64,7 +65,7 @@ public Task<IReadOnlyDictionary<string, JsonNode>> ResolveManyAsync(
6465
public Task<string> SetAsync(string path, JsonNode value, IVariableProviderContext context)
6566
=> KeyVaultExtension.HandleKeyVaultException(async () =>
6667
{
67-
if (value.GetSchemaValueType() != SchemaValueType.String)
68+
if (value.GetValueKind() != JsonValueKind.String)
6869
{
6970
throw new NotSupportedException("KeyVault only supports String secrets");
7071
}

0 commit comments

Comments
 (0)