Skip to content

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

Merged
askpt merged 12 commits into
open-feature:mainfrom
kylejuliandev:feat/add-flagd-inprocess-json-schema-validation
May 12, 2025
Merged

askpt merged 12 commits into
open-feature:mainfrom
kylejuliandev:feat/add-flagd-inprocess-json-schema-validation

Conversation

@kylejuliandev

Copy link
Copy Markdown
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>

@askpt askpt left a comment

Copy link
Copy Markdown
Member

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!

<!-- 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
Copy Markdown
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Have bumped it down to 11.0.0, you're right there is no need to tie Flagd to 11.2 if it works just as well at 11.0

return;
}

#if NET5_0_OR_GREATER

Copy link
Copy Markdown
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
Copy Markdown
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have refactored these tests now to have the constructor initialise the JsonEvaluator. A lot of duplicated code removed now 😄

Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
kylejuliandev and others added 2 commits May 2, 2025 20:35
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>

# Conflicts:
#	src/OpenFeature.Contrib.Providers.Flagd/Resolver/InProcess/InProcessResolver.cs
@askpt
askpt merged commit 5037f60 into open-feature:main May 12, 2025
@kylejuliandev
kylejuliandev deleted the feat/add-flagd-inprocess-json-schema-validation branch May 12, 2025 07:58
weyert pushed a commit to weyert/dotnet-sdk-contrib that referenced this pull request May 30, 2025
…ode is used (open-feature#373)

Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
Co-authored-by: André Silva <2493377+askpt@users.noreply.github.com>
Signed-off-by: Weyert de Boer <weyert@innerfuse.biz>
weyert pushed a commit to weyert/dotnet-sdk-contrib that referenced this pull request Jun 19, 2025
…ode is used (open-feature#373)

Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
Co-authored-by: André Silva <2493377+askpt@users.noreply.github.com>
weyert pushed a commit to weyert/dotnet-sdk-contrib that referenced this pull request Jun 19, 2025
…ode is used (open-feature#373)

Signed-off-by: Kyle Julian <38759683+kylejuliandev@users.noreply.github.com>
Co-authored-by: André Silva <2493377+askpt@users.noreply.github.com>
Signed-off-by: Weyert de Boer <weyert@innerfuse.biz>
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