Skip to content
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

Allow Comment in OpcPublisher Configuration when Validation is used #1892

Merged
merged 2 commits into from
Nov 8, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,15 @@ public IList<JsonSchemaValidationResult> Validate(byte[] jsonBuffer, TextReader
// Run validation ensuring that trailing commas are supported
// as it appears trailing commas have been allowable in the
// configuration files for some time.
// Allow but Skip Commends
var validationResults = schema.Validate(
JsonDocument.Parse(
jsonStringWithoutBom,
new JsonDocumentOptions() { AllowTrailingCommas = true, }
).RootElement,
new JsonDocumentOptions()
{
AllowTrailingCommas = true,
CommentHandling = JsonCommentHandling.Skip
}).RootElement,
validationOptions);

var jsonSchemaValidationResultCollection = new List<JsonSchemaValidationResult>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,34 @@ public void ConfigurationFileWithLargeErrorListIsHandledSuccessfully() {
}
}

[Fact]
public void ConfigurationFileWithCommendIsAllowed() {
using var schemaReader = new StreamReader(PublishedNodesSchema);
var configFileShell = @"
// This header commend does not throws validation error
[
{
/* This endpoint is simulated */
""EndpointUrl"": ""opc.tcp://20.185.195.172:53530/OPCUA/SimulationServer"",
// No Security 😉
""UseSecurity"": false,
""OpcNodes"": [
{
// First Node
""Id"": ""i=1001"",
""OpcSamplingInterval"": 2000,
""OpcPublishingInterval"": 5000,
}
]
}
]
";
var validator = new JsonSchemaDotNetSchemaValidator();
var results = validator.Validate(Encoding.UTF8.GetBytes(configFileShell), schemaReader);

Assert.True(results.First().IsValid);
}

private string testConfiguration = @"
[
{
Expand Down