Skip to content

Refactor formatter config to reqnroll json config#1024

Draft
clrudolphi wants to merge 6 commits intomainfrom
Refactor_Formatter_Config_to_Reqnroll_JsonConfig
Draft

Refactor formatter config to reqnroll json config#1024
clrudolphi wants to merge 6 commits intomainfrom
Refactor_Formatter_Config_to_Reqnroll_JsonConfig

Conversation

@clrudolphi
Copy link
Copy Markdown
Contributor

🤔 What's changed?

Refactored the primary interface of Formatters configuration from an untyped dictionary to a class with support for additional properties.
The 'formatters' element of the reqnroll.json has been added to the JsonConfig structure so that Reqnroll's configuration deserialization logic is used to load the formatter config.

These changes cause a breaking change in the contract of FormatterBase, so this should only be targeted at next major release.

⚡️ What's your motivation?

Better alignment with overall Reqnroll configuration mechanisms.

🏷️ What kind of change is this?

  • 🏦 Refactoring/debt/DX (improvement to code design, tooling, etc. without changing behaviour)
  • 💥 Breaking change (incompatible changes to the API)

♻️ Anything particular you want feedback on?

At this point, the source generator JsonConfig is used for deserialization, but the formatters element is not yet added to the ReqnrollConfiguration class structure.

📋 Checklist:

  • I've changed the behaviour of the code
    • I have added/updated tests to cover my changes.
  • My change requires a change to the documentation.
    • I have updated the documentation accordingly.
  • Users should know about my change
    • I have added an entry to the "[vNext]" section of the CHANGELOG, linking to this pull request & included my GitHub handle to the release contributors list.

This text was originally taken from the template of the Cucumber project, then edited by hand. You can modify the template here.

…g for deserializing the reqnroll.config content to obtain the Formatters configuration.
…ion from an untyped Dictionary<> to a typed contract that supports untyped additional properties.
@clrudolphi clrudolphi requested a review from gasparnagy February 3, 2026 20:09
@gasparnagy
Copy link
Copy Markdown
Contributor

gasparnagy commented Feb 18, 2026

@clrudolphi is this work in progress still, or read for review?

@clrudolphi
Copy link
Copy Markdown
Contributor Author

@clrudolphi is this work in progress still, or read for review?

This accomplishes what I had set out to do.
However, it does not pull Formatter configs into the main Reqnroll Configuration class and data flow.

Would you like to see it fully incorporated?

@gasparnagy
Copy link
Copy Markdown
Contributor

This accomplishes what I had set out to do. However, it does not pull Formatter configs into the main Reqnroll Configuration class and data flow.

Would you like to see it fully incorporated?

No, that's OK. I will check it next week.

@clrudolphi
Copy link
Copy Markdown
Contributor Author

No, that's OK. I will check it next week.

Re-ping on this. Is there more work you'd like to see on this before we move forward?

Copy link
Copy Markdown
Contributor

@gasparnagy gasparnagy left a comment

Choose a reason for hiding this comment

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

I think the direction is good. I have made some comments.

Comment thread Reqnroll/Formatters/Configuration/IFormattersConfigurationProvider.cs Outdated

try
{
var jsonConfig = JsonSerializer.Deserialize(jsonContent, JsonConfigurationSourceGenerator.Default.JsonConfig);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do I get it right, that this is going to be removed once the PR is complete, as we can simply get the deserialized config from Reqnroll, right?

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.

That was not my intent; but I do see where this is awkward. I was attempting to use this extractor for two situations: regular configuration via the reqnroll.config file and for the situation of when a user overrides formatter configuration using an environment variable REQNROLL_FORMATTERS (as a json string).

This PR only goes so far as to re-use the Json source generators for deserialization. The formatters configuration subsystem is independently finding and reading the reqnroll.config file content.
I don't yet have the ReqnrollConfiguration object modified to have a Formatters property.

Even/when we go that far, we still need this "extractor" code to handle the override of Formatters config via Environment variable.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yes, we would anyway need this code, but only use it for the env overrides.

But I'm fine going step-by-step and keep it like as it is for this PR.

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 went ahead and integrated the formatters configuration reading with ReqnrollConfiguration and the ConfigurationLoader.
The extractor is retained for use by the Json Environment variable override provider.

/// Captures any additional/custom formatters not explicitly defined above.
/// </summary>
[JsonExtensionData]
public Dictionary<string, JsonElement> AdditionalFormatters { get; set; }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this not a Dictionary<string,FormatterOptionsElement>?

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 haven't found a way to do that directly. The Json source generator limits extension data to JsonElements, JsonNodes, or objects.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

But we could make the whole thing as a Dictionary<string,FormatterOptionsElement>, right? That would implicitly contain html and message as keys, but we could make prop getters to access them easily.

Comment thread Reqnroll/Formatters/Configuration/FormatterConfiguration.cs
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.

2 participants