-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into NMSHDB-145-Backbone-Support-Show-sent-and-re…
…ceived-messages-of-an-identity
- Loading branch information
Showing
23 changed files
with
215 additions
and
184 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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
65 changes: 65 additions & 0 deletions
65
AdminApi/test/AdminApi.Tests.Integration/Support/JsonValidator.cs
This file contains 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,65 @@ | ||
using Newtonsoft.Json; | ||
using Newtonsoft.Json.Linq; | ||
using NJsonSchema; | ||
using NJsonSchema.NewtonsoftJson.Generation; | ||
using JsonSchemaGenerator = NJsonSchema.Generation.JsonSchemaGenerator; | ||
|
||
namespace Backbone.AdminApi.Tests.Integration.Support; | ||
|
||
public class JsonValidator | ||
{ | ||
private static readonly Dictionary<Type, JsonSchema> CACHED_SCHEMAS = new(); | ||
|
||
public static async Task<(bool IsValid, IList<string> Errors)> ValidateJsonSchema<T>(string json) | ||
{ | ||
var errors = new List<string>(); | ||
|
||
if (CACHED_SCHEMAS.TryGetValue(typeof(T), out var schema)) | ||
{ | ||
try | ||
{ | ||
var parsedJson = JObject.Parse(json); | ||
return CreateValueTupleResult(schema, parsedJson, errors); | ||
} | ||
catch (JsonReaderException) | ||
{ | ||
var parsedJson = JArray.Parse(json); | ||
return CreateValueTupleResult(schema, parsedJson, errors); | ||
} | ||
} | ||
|
||
var settings = new NewtonsoftJsonSchemaGeneratorSettings(); | ||
|
||
var generator = new JsonSchemaGenerator(settings); | ||
|
||
var schemaJson = generator.Generate(typeof(T)); | ||
|
||
var generatedSchema = schemaJson.ToJson(); | ||
|
||
schema = await JsonSchema.FromJsonAsync(generatedSchema); | ||
|
||
schema.AllowAdditionalProperties = true; | ||
|
||
CACHED_SCHEMAS.Add(typeof(T), schema); | ||
|
||
try | ||
{ | ||
var responseJson = JObject.Parse(json); | ||
return CreateValueTupleResult(schema, responseJson, errors); | ||
} | ||
catch (JsonReaderException) | ||
{ | ||
var responseJson = JArray.Parse(json); | ||
return CreateValueTupleResult(schema, responseJson, errors); | ||
} | ||
} | ||
|
||
private static (bool IsValid, IList<string> Errors) CreateValueTupleResult(JsonSchema schema, JToken parsedJson, List<string> errors) | ||
{ | ||
var validationResults = schema.Validate(parsedJson); | ||
|
||
errors.AddRange(validationResults.Select(validationResult => validationResult.ToString())); | ||
|
||
return (validationResults.Count == 0, errors); | ||
} | ||
} |
54 changes: 0 additions & 54 deletions
54
AdminApi/test/AdminApi.Tests.Integration/Validators/JsonValidators.cs
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
BuildingBlocks/src/BuildingBlocks.SDK/BuildingBlocks.SDK.csproj
This file contains 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.