Skip to content

feat: add JSON Schema validation for Flagd provider when in-process mode is used #373

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
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

kylejuliandev
Copy link
Contributor

This PR

  • Adds NJsonSchema to validate Flagd configurations when in-process mode is used. Schemas used are: Flags and targeting

Related Issues

Fixes #226

Notes

Not yet quite finished. Needs some unit tests. Initial testing locally seems to suggest it is working as expected

image

I'm not sure how keen I am on extending FlagdConfig.cs with ILogger. An alternative approach might be to make it more first class by tweaking the constructor of the FlagdProvider.cs

public FlagdProvider(FlagdConfig config, ILogger logger)
{
    // ... other config setup

    if (logger == null)
    {
        logger = NullLogger.Instance;
    }
    _logger = logger
}

Follow-up Tasks

How to test

* Fix unit tests failing due to change in constructor
* Add initial documentation to README
* Add ILogger to provider config

Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
@kylejuliandev kylejuliandev marked this pull request as ready for review April 28, 2025 18:17
@kylejuliandev kylejuliandev requested review from a team as code owners April 28, 2025 18:17
Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
Copy link
Member

@askpt askpt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a minor comment in relation to the NJsonSchema version. The rest are minor nitpicks. Great job!

@@ -24,6 +24,7 @@
<!-- The generated files will be placed in ./obj/Debug/netstandard2.0/Protos -->
<PackageReference Include="JsonLogic" Version="5.4.0" />
<PackageReference Include="murmurhash" Version="1.0.3" />
<PackageReference Include="NJsonSchema" Version="11.2.0" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will you get a lot of breaking changes if you lower to 11.0.0? Since we are publishing this dependency (NJsonSchema), we shouldn't enforce newest versions.

return;
}

#if NET5_0_OR_GREATER
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not as part of this PR, but we should bump the target framework...

Comment on lines +18 to +20
var jsonSchemaValidator = Substitute.For<IJsonSchemaValidator>();

var jsonEvaluator = new JsonEvaluator(fixture.Create<string>());
var jsonEvaluator = new JsonEvaluator(fixture.Create<string>(), jsonSchemaValidator);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A lot of copy-paste here. I think we should move into a ctor, and control the flow here if needs any change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[flagd] Add targeting validation and log warning
4 participants