Skip to content

Fix multi-file output directory validation#1172

Merged
christianhelle merged 6 commits into
mainfrom
fix-multiple-files-contracts-output-folder
Jun 28, 2026
Merged

Fix multi-file output directory validation#1172
christianhelle merged 6 commits into
mainfrom
fix-multiple-files-contracts-output-folder

Conversation

@christianhelle

@christianhelle christianhelle commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Description:

  • reject file-like output paths in multi-file mode for CLI and .refitter directory settings
  • add regression coverage for direct and indirect multi-file activation paths
  • clarify multi-file output docs and update smoke tests to use directory paths

Closes #1169

Example OpenAPI Specifications:

N/A

Example generated Refit interface

N/A

Validation:

  • dotnet build -c Release src/Refitter.slnx
  • dotnet test --solution src/Refitter.slnx -c Release
  • dotnet format --verify-no-changes src/Refitter.slnx

Summary by CodeRabbit

  • New Features
    • Improved multi-file generation validation for --output and --contracts-output, including clearer handling of when these values look like file paths vs directory paths.
  • Documentation
    • Updated CLI usage and .refitter format docs with multi-file directory-path requirements and clarified --output vs --contracts-output behavior.
  • Tests
    • Expanded CLI and settings-file test coverage for valid/invalid multi-file output combinations.
    • Adjusted smoke-test output behavior for the multiple-files contract-only combination.
  • Chores
    • Minor formatting/namespace cleanup.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: a278e971-b06f-4fb7-857a-9f36459aaf42

📥 Commits

Reviewing files that changed from the base of the PR and between 87812f9 and 1d1b7db.

📒 Files selected for processing (2)
  • src/Refitter/GenerateCommand.cs
  • src/Refitter/SettingsValidator.cs
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/Refitter/GenerateCommand.cs
  • src/Refitter/SettingsValidator.cs

📝 Walkthrough

Walkthrough

Multi-file output handling now validates directory-style paths in CLI and settings-file flows, with updated docs, help text, and tests. Several core enum and utility files were also reformatted to file-scoped namespaces, and one test file’s using order changed.

Changes

Multi-file output validation

Layer / File(s) Summary
CLI and settings docs
README.md, src/Refitter/README.md, src/Refitter/Settings.cs
CLI usage, option help, and .refitter settings text now describe multi-file output as directory-based and note the path requirements for --output and --contracts-output.
Validation plumbing
src/Refitter/GenerateCommand.cs, src/Refitter/SettingsValidator.cs
GenerateCommand passes whether --output was explicitly provided, and SettingsValidator uses that flag while checking multi-file output paths in CLI and settings-file flows.
Regression tests
src/Refitter.Tests/GenerateCommandTests.cs, src/Refitter.Tests/SettingsFile/SettingsValidatorTests.cs, test/smoke-tests.bat, test/smoke-tests.ps1
Unit and smoke tests cover multi-file directory-path success cases, file-like output failures, and the contract-only multiple-files combo output path.

Namespace formatting cleanup

Layer / File(s) Summary
Namespace formatting
src/Refitter.Core/Settings/CacheProviderType.cs, src/Refitter.Core/Settings/MappingProviderType.cs, src/Refitter.Core/Utilities/VersionHelper.cs, src/Refitter.Tests/OpenApi/OpenApiValidatorTests.cs
The two enum files switch to file-scoped namespaces, VersionHelper removes a formatting artifact, and OpenApiValidatorTests reorders its using directives.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested labels

bugfix

Poem

I’m a rabbit with a careful nose,
I hop where --multiple-files goes.
Directories in, surprises out,
No stray .cs paths to fret about.
🐇✨ Thump-thump, the tests all bloom.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR includes unrelated formatting-only edits in enum files, a namespace/whitespace cleanup, and a test using-order swap beyond the issue scope. Split out the unrelated formatting and cleanup changes into a separate PR, keeping this one focused on multi-file output validation, docs, and tests.
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 (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: validating multi-file output directories.
Linked Issues check ✅ Passed The changes address #1169 by rejecting file-like outputs in multi-file mode, covering direct and indirect activation, docs, tests, and smoke updates.
✨ 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 fix-multiple-files-contracts-output-folder

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.

@christianhelle christianhelle self-assigned this Jun 26, 2026
@christianhelle christianhelle added enhancement New feature, bug fix, or request .NET Pull requests that contain changes to .NET code labels Jun 26, 2026

@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: 2

🧹 Nitpick comments (3)
src/Refitter/Settings.cs (1)

38-45: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add XML docs to the updated public CLI settings members.

These changed public properties still rely only on [Description]. Please add /// <summary> docs so the public API stays consistent with the C# guideline for surfaced members.

As per coding guidelines, "Include XML documentation for public APIs in C# code".

Also applies to: 129-139

🤖 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/Refitter/Settings.cs` around lines 38 - 45, The public CLI settings
properties in Settings are currently documented only with [Description], so add
XML <summary> comments for the updated surfaced members to keep the public API
consistent with C# guidelines. Update the relevant properties in the settings
class, including OutputPath and the other affected public CLI option members
referenced by the change, and ensure each has a clear XML doc summary matching
its existing description.

Source: Coding guidelines

src/Refitter.Tests/GenerateCommandTests.cs (1)

45-127: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Add the required scenario coverage for this feature as well.

These validator-level tests are good regressions, but they do not satisfy the repo rule for new OpenAPI features to also have Refitter.Tests.Scenarios coverage with generate → assert → build, including both OpenAPI 2.0 and 3.0 specs. That extra layer is what will catch end-to-end path handling regressions beyond the validator result string.

As per coding guidelines, "New features must have unit tests in the Refitter.Tests.Scenarios namespace following the pattern: spec string → generate → assert → build" and "Test with both OpenAPI 2.0 and 3.0 specifications when working with OpenAPI specifications".

🤖 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/Refitter.Tests/GenerateCommandTests.cs` around lines 45 - 127, The new
output-path validation behavior also needs end-to-end scenario coverage, not
just SettingsValidator unit tests. Add Refitter.Tests.Scenarios tests that
follow the existing generate → assert → build pattern and verify both
single-file and multiple-files output handling. Use the scenario helpers around
the generate command and assert the produced files for both OpenAPI 2.0 and
OpenAPI 3.0 specs. Place the new coverage alongside the existing scenario tests
so regressions in SettingsValidator and the generation flow are caught together.

Source: Coding guidelines

src/Refitter/SettingsValidator.cs (1)

218-235: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Duplicated CLI --output override check across both validators.

Lines 218-226 and 248-256 are identical. Extracting a shared helper (e.g. TryGetCliOutputOverrideError(settings, outputPathSpecified)) would remove the duplication and keep the error wording in sync.

Also applies to: 248-266

🤖 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/Refitter/SettingsValidator.cs` around lines 218 - 235, The CLI `--output`
override validation is duplicated in both validators, so extract the repeated
`HasExplicitCliOutputOverride` and `IsFileLikePath` checks into a shared helper
such as `TryGetCliOutputOverrideError` in `SettingsValidator`. Have both
validation paths call that helper and return its
`GetCliMultiFilePathValidationError` result so the `--output` wording stays
consistent in one place and the duplicate blocks are removed.
🤖 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/Refitter/GenerateCommand.cs`:
- Around line 32-34: The output path detection in GenerateCommand is missing the
combined argument form, so explicit values like --output=... are treated as
unspecified. Update the context.Arguments check in GenerateCommand to recognize
both the plain flags and the prefix forms by using the same outputPathSpecified
logic with StartsWith for --output= and -o= alongside the existing Equals
checks.

In `@src/Refitter/SettingsValidator.cs`:
- Around line 358-369: IsFileLikePath is too broad because it treats any path
with a non-empty extension as a file, which incorrectly rejects valid output
directories like Generated.Api or v1.0. Update SettingsValidator.IsFileLikePath
to only return true for known source/config file extensions instead of using
Path.GetExtension generically. Keep the existing normalization and null/empty
checks, but replace the extension heuristic with a fixed allowlist of file types
used by Refitter settings and outputs.

---

Nitpick comments:
In `@src/Refitter.Tests/GenerateCommandTests.cs`:
- Around line 45-127: The new output-path validation behavior also needs
end-to-end scenario coverage, not just SettingsValidator unit tests. Add
Refitter.Tests.Scenarios tests that follow the existing generate → assert →
build pattern and verify both single-file and multiple-files output handling.
Use the scenario helpers around the generate command and assert the produced
files for both OpenAPI 2.0 and OpenAPI 3.0 specs. Place the new coverage
alongside the existing scenario tests so regressions in SettingsValidator and
the generation flow are caught together.

In `@src/Refitter/Settings.cs`:
- Around line 38-45: The public CLI settings properties in Settings are
currently documented only with [Description], so add XML <summary> comments for
the updated surfaced members to keep the public API consistent with C#
guidelines. Update the relevant properties in the settings class, including
OutputPath and the other affected public CLI option members referenced by the
change, and ensure each has a clear XML doc summary matching its existing
description.

In `@src/Refitter/SettingsValidator.cs`:
- Around line 218-235: The CLI `--output` override validation is duplicated in
both validators, so extract the repeated `HasExplicitCliOutputOverride` and
`IsFileLikePath` checks into a shared helper such as
`TryGetCliOutputOverrideError` in `SettingsValidator`. Have both validation
paths call that helper and return its `GetCliMultiFilePathValidationError`
result so the `--output` wording stays consistent in one place and the duplicate
blocks are removed.
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b832f1cd-88f6-4a4d-84da-3d1c605b488a

📥 Commits

Reviewing files that changed from the base of the PR and between 3c7a468 and 87812f9.

📒 Files selected for processing (13)
  • README.md
  • src/Refitter.Core/Settings/CacheProviderType.cs
  • src/Refitter.Core/Settings/MappingProviderType.cs
  • src/Refitter.Core/Utilities/VersionHelper.cs
  • src/Refitter.Tests/GenerateCommandTests.cs
  • src/Refitter.Tests/OpenApi/OpenApiValidatorTests.cs
  • src/Refitter.Tests/SettingsFile/SettingsValidatorTests.cs
  • src/Refitter/GenerateCommand.cs
  • src/Refitter/README.md
  • src/Refitter/Settings.cs
  • src/Refitter/SettingsValidator.cs
  • test/smoke-tests.bat
  • test/smoke-tests.ps1

Comment thread src/Refitter/GenerateCommand.cs Outdated
Comment thread src/Refitter/SettingsValidator.cs
@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.82%. Comparing base (89c0c92) to head (1d1b7db).
⚠️ Report is 10 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1172   +/-   ##
=======================================
  Coverage   94.82%   94.82%           
=======================================
  Files          80       80           
  Lines        3553     3557    +4     
=======================================
+ Hits         3369     3373    +4     
  Misses         75       75           
  Partials      109      109           
Flag Coverage Δ
unittests 94.82% <ø> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai

coderabbitai Bot commented Jun 27, 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 2 unresolved review comments.

Files modified:

  • src/Refitter/GenerateCommand.cs
  • src/Refitter/SettingsValidator.cs

Commit: 1d1b7db2af0d0b3ba49f11603fdbd3a7f2f7302b

The changes have been pushed to the fix-multiple-files-contracts-output-folder branch.

Time taken: 2m 7s

Fixed 2 file(s) based on 2 unresolved review comments.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
@christianhelle
christianhelle merged commit fe42089 into main Jun 28, 2026
13 checks passed
@christianhelle
christianhelle deleted the fix-multiple-files-contracts-output-folder branch June 28, 2026 21:51
@sonarqubecloud

Copy link
Copy Markdown

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

Labels

enhancement New feature, bug fix, or request .NET Pull requests that contain changes to .NET code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using the --multiple-files argument generates Contracts.cs under a folder called Output.cs

1 participant