-
Notifications
You must be signed in to change notification settings - Fork 299
#3053 Fix by using custom bool parsing that if a string is found then… #3054
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
simonsabin
wants to merge
18
commits into
Azure:main
Choose a base branch
from
simonsabin:3053BooleanEnvSub
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+292
−10
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
add53ed
#3053 Fix by using custom bool parsing that if a string is found then…
simonsabin 05b3586
Update src/Service.Tests/UnitTests/RuntimeConfigLoaderJsonDeserialize…
simonsabin 0b6e7f3
Update src/Config/Converters/BooleanJsonConverterFactory.cs
simonsabin c1759af
Update src/Config/Converters/BooleanJsonConverterFactory.cs
simonsabin 36621c6
Update src/Service.Tests/UnitTests/RuntimeConfigLoaderJsonDeserialize…
simonsabin 76b0c41
Extra handling of numeric values and test coverage
simonsabin 5c7f38a
rename file to match class
simonsabin 7532d68
Add schema solution
simonsabin bcf15b2
Merge branch 'main' into 3053BooleanEnvSub
simonsabin e3eee4a
Add test to validate the pattern matching for string booleans
simonsabin 17f1067
Apply flexible enabled to rest, graphql, health and application-insghts
simonsabin d531999
Merge branch 'main' into 3053BooleanEnvSub
simonsabin 2edb0e4
fix formatting
simonsabin aba610e
Merge branch '3053BooleanEnvSub' of https://github.com/simonsabin/dat…
simonsabin 856052c
Normalise line endings
simonsabin 6b24404
update to all for any 3 letter prefix for substitution
simonsabin af5dee4
Better exception if null found
simonsabin 2eaf189
Update src/Config/Converters/BooleanJsonConverter.cs
simonsabin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System.Text.Json; | ||
| using System.Text.Json.Serialization; | ||
|
|
||
| namespace Azure.DataApiBuilder.Config.Converters; | ||
|
|
||
| /// <summary> | ||
| /// JSON converter for boolean values that also supports string representations such as | ||
| /// "true", "false", "1", and "0". Any environment variable replacement is handled by | ||
| /// other converters (for example, the string converter) before the value is parsed here. | ||
| public class BoolJsonConverter : JsonConverter<bool> | ||
| { | ||
|
|
||
| public override bool Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) | ||
| { | ||
| if (reader.TokenType is JsonTokenType.Null) | ||
| { | ||
|
|
||
| throw new JsonException("Unexpected null JSON token. Expected a boolean literal or a valid @expression."); | ||
| } | ||
|
|
||
| if (reader.TokenType == JsonTokenType.String) | ||
| { | ||
|
|
||
| string? tempBoolean = JsonSerializer.Deserialize<string>(ref reader, options); | ||
|
|
||
| bool result = tempBoolean?.ToLower() switch | ||
| { | ||
| //numeric values have to be checked here as they may come from string replacement | ||
| "true" or "1" => true, | ||
| "false" or "0" => false, | ||
| _ => throw new JsonException($"Invalid boolean value: {tempBoolean}. Specify either true or false."), | ||
| }; | ||
|
|
||
| return result; | ||
| } | ||
| else if (reader.TokenType == JsonTokenType.Number) | ||
| { | ||
| bool result = reader.GetInt32() switch | ||
| { | ||
| 1 => true, | ||
| 0 => false, | ||
| _ => throw new JsonException($"Invalid boolean value. Specify either true or false."), | ||
| }; | ||
| return result; | ||
| } | ||
| else | ||
| { | ||
| return reader.GetBoolean(); | ||
| } | ||
|
|
||
| throw new JsonException("Invalid JSON value. Expected a boolean literal or a valid @expression."); | ||
| } | ||
|
|
||
| public override void Write(Utf8JsonWriter writer, bool value, JsonSerializerOptions options) | ||
| { | ||
| writer.WriteBooleanValue(value); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.