Skip to content

Add explicit support for OpenAPI configuration files - #1604

Open
christianhelle wants to merge 3 commits into
masterfrom
rapicgen-openapi-generator-config-file-support
Open

Add explicit support for OpenAPI configuration files#1604
christianhelle wants to merge 3 commits into
masterfrom
rapicgen-openapi-generator-config-file-support

Conversation

@christianhelle

@christianhelle christianhelle commented Jun 22, 2026

Copy link
Copy Markdown
Owner

This pull request adds support for specifying an explicit OpenAPI Generator configuration file when generating C# code from OpenAPI specs, and improves configuration file handling throughout the codebase. The changes also update the documentation and add tests to ensure correct behavior.

OpenAPI Generator configuration file support:

  • Added a new --config-file option to the CLI (OpenApiCSharpGeneratorCommandSettings) to allow users to specify an explicit OpenAPI Generator configuration file path.
  • Updated the generator logic (OpenApiCSharpCodeGenerator) to prioritize the explicit configuration file if provided, falling back to auto-discovery only if not specified.
  • Extended the generator options interfaces and implementations (IOpenApiGeneratorOptions, DefaultOpenApiGeneratorOptions, OpenApiGeneratorOptionsPage, and VSIX settings) to support the new ConfigurationFile property. [1] [2] [3] [4]

Testing and documentation:

  • Added a test to ensure that the explicit configuration file is used when specified (OpenApiCSharpCodeGeneratorTests).
  • Updated the README.md to document the new --config-file option and explain the auto-discovery mechanism for configuration files.

Code quality:

  • Minor improvements to test imports and organization.

Summary by CodeRabbit

  • New Features
    • Added --config-file <path> option to explicitly provide an OpenAPI Generator configuration file (takes precedence over auto-discovery).
    • Added a “Configuration File” option to the Visual Studio extension to override auto-discovery.
  • Documentation
    • Updated README to describe --config-file and the auto-discovery naming patterns: <spec>.config.<ext>, <spec>.config.json, <spec>.config.yaml.
  • Tests
    • Added coverage to verify the generator uses the explicitly provided configuration file and passes it to the OpenAPI Generator invocation.

@christianhelle christianhelle self-assigned this Jun 22, 2026
@christianhelle christianhelle added enhancement New feature or request .NET Pull requests that update .net code labels Jun 22, 2026
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a ConfigurationFile option to the OpenAPI CSharp generator path. The option is added to shared options, surfaced in CLI and VSIX settings, consumed by the core generator as -c "<path>", and covered by a new test and README update.

Changes

ConfigurationFile option end-to-end

Layer / File(s) Summary
IOpenApiGeneratorOptions contract and options model
src/Core/ApiClientCodeGen.Core/Options/OpenApiGenerator/IOpenApiGeneratorOptions.cs, src/Core/ApiClientCodeGen.Core/Options/OpenApiGenerator/DefaultOpenApiGeneratorOptions.cs
string? ConfigurationFile is added to the interface and its default implementation.
Core generator -c argument injection
src/Core/ApiClientCodeGen.Core/Generators/OpenApi/OpenApiCSharpCodeGenerator.cs
GenerateCode adds a branch that resolves ConfigurationFile to an absolute path and appends -c "<path>" to the generator command; UseConfigurationFile becomes the else if fallback.
CLI and VSIX settings wiring
src/CLI/ApiClientCodeGen.CLI/Commands/CSharp/OpenApiCSharpGeneratorCommand.cs, src/VSIX/ApiClientCodeGen.VSIX.Shared/Options/OpenApiGenerator/OpenApiGeneratorOptionsPage.cs, src/VSIX/ApiClientCodeGen.VSIX.Extensibility/Settings/OpenApiGeneratorSettings.cs, src/VSIX/ApiClientCodeGen.VSIX.Extensibility/Settings/ExtensionSettingsProvider.cs
--config-file is added to the CLI command settings, ConfigurationFile is added to the VSIX options page, and the matching stored setting is defined and mapped into generator options.
Test coverage and documentation
src/Core/ApiClientCodeGen.Core.Tests/Generators/OpenApi/OpenApiCSharpCodeGeneratorTests.cs, README.md
A new xUnit [Fact] verifies that GenerateCode passes -c "<configFile>" when ConfigurationFile is set, and the README documents the option and adjacent auto-discovery naming patterns.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • christianhelle/apiclientcodegen#1591: Both PRs modify OpenApiCSharpCodeGenerator’s GenerateCode/OpenAPI Generator invocation; the retrieved PR refactors execution to use ToolRunner.RunJava, while this PR adds an explicit -c "<configFile>" option.

Suggested labels

documentation

Poem

🐇 I hop from setting to setting so neat,
-c found its config-file seat.
In CLI, VSIX, and code paths too,
the generator sings a more focused tune.
README rustles, a tidy refrain—
and bunny-approved configs now մն?

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding explicit OpenAPI configuration file support.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch rapicgen-openapi-generator-config-file-support

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/VSIX/ApiClientCodeGen.VSIX.Extensibility/Settings/ExtensionSettingsProvider.cs (1)

92-113: 🎯 Functional Correctness | 🔴 Critical

Add missing OpenApiConfigurationFile setting and populate ConfigurationFile property.

The ConfigurationFile property (line 223) is declared but never initialized from settings. Unlike TemplatesPath (line 222), which reads from OpenApiGeneratorSettings.OpenApiTemplatesPath, there is no corresponding OpenApiConfigurationFile setting defined in OpenApiGeneratorSettings.cs. The setting must be created as a String setting, then added to the read list in GetOpenApiGeneratorOptionsAsync (lines 94-109) and used to initialize the ConfigurationFile property.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@src/VSIX/ApiClientCodeGen.VSIX.Extensibility/Settings/ExtensionSettingsProvider.cs`
around lines 92 - 113, The ConfigurationFile property is declared but never
populated from settings, unlike the TemplatesPath property which correctly reads
from OpenApiGeneratorSettings.OpenApiTemplatesPath. First, add a new String
setting constant called OpenApiConfigurationFile to the OpenApiGeneratorSettings
class (following the pattern of OpenApiTemplatesPath). Then, add this new
OpenApiConfigurationFile setting to the settings array parameter in the
ReadAsync call within the GetOpenApiGeneratorOptionsAsync method (lines 94-109).
Finally, ensure that the OpenApiOptions constructor or the method that populates
it uses the retrieved value to initialize the ConfigurationFile property,
matching how TemplatesPath is currently being handled.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@src/VSIX/ApiClientCodeGen.VSIX.Extensibility/Settings/ExtensionSettingsProvider.cs`:
- Line 223: The ConfigurationFile property is declared but not initialized from
the settings values like other properties in the class (e.g., TemplatesPath).
Initialize the ConfigurationFile property by reading from the values dictionary
using the appropriate OpenApiGeneratorSettings key (OpenApiConfigurationFile or
similar), following the same pattern as TemplatesPath at line 222. Additionally,
add this setting key to the list of settings being retrieved in the
GetOpenApiGeneratorOptionsAsync method (lines 94-109) to ensure the value is
actually fetched and available in the values dictionary.

---

Outside diff comments:
In
`@src/VSIX/ApiClientCodeGen.VSIX.Extensibility/Settings/ExtensionSettingsProvider.cs`:
- Around line 92-113: The ConfigurationFile property is declared but never
populated from settings, unlike the TemplatesPath property which correctly reads
from OpenApiGeneratorSettings.OpenApiTemplatesPath. First, add a new String
setting constant called OpenApiConfigurationFile to the OpenApiGeneratorSettings
class (following the pattern of OpenApiTemplatesPath). Then, add this new
OpenApiConfigurationFile setting to the settings array parameter in the
ReadAsync call within the GetOpenApiGeneratorOptionsAsync method (lines 94-109).
Finally, ensure that the OpenApiOptions constructor or the method that populates
it uses the retrieved value to initialize the ConfigurationFile property,
matching how TemplatesPath is currently being handled.
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f35669ec-7217-4fef-b3ac-a8031b23b813

📥 Commits

Reviewing files that changed from the base of the PR and between 5da804a and 5afada3.

📒 Files selected for processing (8)
  • README.md
  • src/CLI/ApiClientCodeGen.CLI/Commands/CSharp/OpenApiCSharpGeneratorCommand.cs
  • src/Core/ApiClientCodeGen.Core.Tests/Generators/OpenApi/OpenApiCSharpCodeGeneratorTests.cs
  • src/Core/ApiClientCodeGen.Core/Generators/OpenApi/OpenApiCSharpCodeGenerator.cs
  • src/Core/ApiClientCodeGen.Core/Options/OpenApiGenerator/DefaultOpenApiGeneratorOptions.cs
  • src/Core/ApiClientCodeGen.Core/Options/OpenApiGenerator/IOpenApiGeneratorOptions.cs
  • src/VSIX/ApiClientCodeGen.VSIX.Extensibility/Settings/ExtensionSettingsProvider.cs
  • src/VSIX/ApiClientCodeGen.VSIX.Shared/Options/OpenApiGenerator/OpenApiGeneratorOptionsPage.cs

@coderabbitai

coderabbitai Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Note

Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it.

Fixes Applied Successfully

Fixed 2 file(s) based on 1 unresolved review comment.

Files modified:

  • src/VSIX/ApiClientCodeGen.VSIX.Extensibility/Settings/ExtensionSettingsProvider.cs
  • src/VSIX/ApiClientCodeGen.VSIX.Extensibility/Settings/OpenApiGeneratorSettings.cs

Commit: bb5a21cc685c0b44433ccdd1b5368b98491469f6

The changes have been pushed to the rapicgen-openapi-generator-config-file-support branch.

Time taken: 4m 28s

Fixed 2 file(s) based on 1 unresolved review comment.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@src/VSIX/ApiClientCodeGen.VSIX.Shared/Options/OpenApiGenerator/OpenApiGeneratorOptions.cs`:
- Line 47: The logging in OpenApiGeneratorOptions currently writes the raw
ConfigurationFile path, which should be sanitized. Update the logging around
Logger.Instance.WriteLine in OpenApiGeneratorOptions so it only reports that a
configuration file was provided or a redacted/safe representation, and avoid
emitting the full path value from ConfigurationFile.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 57c5f93e-5b85-4ac9-8627-447d14c4e084

📥 Commits

Reviewing files that changed from the base of the PR and between bb5a21c and a6bf848.

📒 Files selected for processing (1)
  • src/VSIX/ApiClientCodeGen.VSIX.Shared/Options/OpenApiGenerator/OpenApiGeneratorOptions.cs

@sonarqubecloud

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request .NET Pull requests that update .net code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants