Skip to content

Fix Source Generator not emitting any files#1143

Merged
christianhelle merged 11 commits into
mainfrom
fix-source-generator
Jun 14, 2026
Merged

Fix Source Generator not emitting any files#1143
christianhelle merged 11 commits into
mainfrom
fix-source-generator

Conversation

@christianhelle

@christianhelle christianhelle commented Jun 14, 2026

Copy link
Copy Markdown
Owner

This pull request updates the Refitter source generator test suite and documentation to reflect the current behavior of file generation, and adds a new custom-generated API interface for testing. The most notable changes are the addition of a comprehensive generated interface for test purposes, updates to test naming and comments for clarity, and a significant change in the documentation to describe the actual file output behavior of the source generator.

Test suite improvements and refactoring:

  • Renamed test methods in SourceGeneratorFileIOTests.cs from Test_SourceGenerator_* to Test_CoreGenerator_* for consistency and clarity, and removed outdated comments referencing Roslyn AddSource() and file I/O expectations. The tests now clearly assert that the core generator should not write files to disk, aligning with the current generator's responsibilities. [1] [2] [3] [4] [5]

Documentation update:

  • Updated README.md to state that the Refitter source generator now writes generated files to a Generated folder on disk, which should be committed to source control, instead of emitting code only in-memory via Roslyn AddSource(). The documentation now matches the actual implementation and clarifies the rationale for this approach.

Test asset addition:

  • Added a new, fully-documented, auto-generated API interface IApiInCustomGeneratedFolder in CustomGenerated.cs for use in source generator tests. This interface includes a wide range of RESTful operations and serves as a comprehensive test asset.

Summary by CodeRabbit

  • Documentation

    • Updated generation output documentation to reflect generated files now written to disk in a Generated folder instead of in-memory generation.
  • Tests

    • Refactored and renamed source generator test suite for improved clarity.
  • Chores

    • Updated test project dependencies to use local project reference.

@christianhelle christianhelle self-assigned this Jun 14, 2026
@christianhelle christianhelle added the bug Something isn't working label Jun 14, 2026
@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

RefitterSourceGenerator switches from Roslyn AddSource() in-memory generation to writing .g.cs files directly to disk. The GeneratedCode record drops Code/HintName in favour of OutputPath, new helpers compute paths and write files, the README is updated, tests are renamed to CoreGenerator, and a sample generated file is committed.

Changes

Source Generator On-Disk Output Pivot

Layer / File(s) Summary
GeneratedCode contract and build reference
src/Refitter.SourceGenerator/RefitterSourceGenerator.cs, test/SourceGenerator/Directory.Build.props
GeneratedCode record replaces Code/HintName with OutputPath; test project switches from NuGet PackageReference (v2.0.0) to a local ProjectReference consumed as an analyzer.
On-disk write logic in RefitterSourceGenerator
src/Refitter.SourceGenerator/RefitterSourceGenerator.cs
Generator computes an output path from the .refitter file location and settings, writes UTF-8 .g.cs content to disk with directory creation and content-diffing, and reports the output path in the success diagnostic. Adds GetOutputPath, WriteGeneratedFile, and GetDirectoryName helpers with a SuppressMessage for banned APIs.
README updated for on-disk semantics
src/Refitter.SourceGenerator/README.md
Replaces in-memory AddSource() description with on-disk Generated folder explanation; updates option docs for outputFolder, outputFilename, contractsOutputFolder, and generateMultipleFiles.
FileIO tests renamed and updated
src/Refitter.SourceGenerator.Tests/SourceGeneratorFileIOTests.cs
All four test methods renamed from Test_SourceGenerator_* to Test_CoreGenerator_*; concurrency test validates parallel generation output contains the expected interface signature; OutputFilename test asserts no file is created on disk while generated code is non-empty.
Committed generated output artifact
src/Refitter.SourceGenerator.Tests/CustomGenerated/CustomGenerated.cs
New committed IApiInCustomGeneratedFolder Refit interface with all petstore/store/user HTTP-annotated method signatures, produced by the on-disk generation flow.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • christianhelle/refitter#1131: Directly modifies RefitterSourceGenerator output-path computation and hint-name/diagnostics contracts — the same code surfaces changed in this PR.
  • christianhelle/refitter#1071: Hardens generation flows in RefitterSourceGenerator.cs including path/hint-name collision handling and .refitter spec resolution, overlapping with this PR's path-computation and error-handling changes.

Suggested labels

bugfix, .NET

🐇 Hoppity hop, no more in-memory maze,
Files land on disk in a Generated haze!
OutputPath shines where HintName once stood,
The bunny writes files — just as it should. 🌿
Commit the .g.cs, let the Roslyn rest,
On-disk generation has passed every test! ✅

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 59.38% 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 describes the main change: fixing the source generator to emit files to disk as intended, resolving the core issue addressed throughout the PR.
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 fix-source-generator

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 and usage tips.

@sonarqubecloud

Copy link
Copy Markdown

@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 (2)
src/Refitter.SourceGenerator/README.md (2)

62-64: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix the .refitter example punctuation.

The outputFolder line is missing a trailing comma before outputFilename, which makes the example malformed for copy/paste use.

🤖 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.SourceGenerator/README.md` around lines 62 - 64, The `.refitter`
example in the README has invalid JSON syntax where the outputFolder property is
missing a trailing comma after the value. Add a comma immediately after the
outputFolder value (after the closing quote of "../CustomOutput") to make the
JSON valid and ready for copy/paste use. The comment about the optional default
can remain on the same line after the comma.

63-63: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

outputFilename default in docs does not match generator behavior.

The README says .refitter defaults to Petstore.cs, but implementation currently defaults to <refitter-name>.g.cs (see src/Refitter.SourceGenerator/RefitterSourceGenerator.cs, Line 121). Please align both locations to the real default to avoid configuration mistakes.

Suggested doc fix
-  "outputFilename": "RefitInterface.cs", // Optional. Default=Output.cs for CLI tool
+  "outputFilename": "RefitInterface.g.cs", // Optional. Default=Output.cs for CLI tool, otherwise <.refitter filename>.g.cs for source generator
-- `outputFilename` - Output filename. Default is `Output.cs` when used from the CLI tool, otherwise its the .refitter filename. So `Petstore.refitter` becomes `Petstore.cs`.
+- `outputFilename` - Output filename. Default is `Output.cs` when used from the CLI tool, otherwise it's the `.refitter` filename with `.g.cs`. So `Petstore.refitter` becomes `Petstore.g.cs`.

Also applies to: 191-191

🤖 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.SourceGenerator/README.md` at line 63, The README.md
documentation incorrectly states that the default outputFilename is "Output.cs"
(at line 63) and likely has the same outdated information at line 191, but the
actual implementation in RefitterSourceGenerator.cs defaults to
"<refitter-name>.g.cs". Update both documentation locations in the README to
correctly reflect the actual default value used by the generator, replacing
references to "Output.cs" or incorrect defaults with the correct pattern
"<refitter-name>.g.cs" to ensure users have accurate configuration information.
🧹 Nitpick comments (1)
src/Refitter.SourceGenerator.Tests/SourceGeneratorFileIOTests.cs (1)

40-40: ⚡ Quick win

Rename public test methods to PascalCase without underscores.

These public method names violate the project C# naming rule for public members.
As per coding guidelines, “Use PascalCase for public members, camelCase for parameters and local variables.”

Suggested renames
-public async Task Test_CoreGenerator_DoesNotWriteToFileSystem()
+public async Task TestCoreGeneratorDoesNotWriteToFileSystem()

-public async Task Test_CoreGenerator_ConcurrentGeneration()
+public async Task TestCoreGeneratorConcurrentGeneration()

-public async Task Test_CoreGenerator_GeneratedCodeIsValid()
+public async Task TestCoreGeneratorGeneratedCodeIsValid()

-public async Task Test_CoreGenerator_OutputFilename_NotCreatedOnDisk()
+public async Task TestCoreGeneratorOutputFilenameNotCreatedOnDisk()

Also applies to: 67-67, 92-92, 114-114

🤖 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.SourceGenerator.Tests/SourceGeneratorFileIOTests.cs` at line 40,
Rename the public test methods in SourceGeneratorFileIOTests.cs from snake_case
to PascalCase to comply with C# naming conventions. At line 40, rename
Test_CoreGenerator_DoesNotWriteToFileSystem to
TestCoreGeneratorDoesNotWriteToFileSystem. At line 67, rename the test method
there to PascalCase (removing underscores). At line 92, rename the test method
there to PascalCase (removing underscores). At line 114, rename the test method
there to PascalCase (removing underscores). Ensure all public test method names
follow PascalCase convention without underscores as separators.

Source: Coding guidelines

🤖 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.SourceGenerator/README.md`:
- Around line 7-9: Remove the informal parenthetical note "(Translation: I
couldn't for the life of me figure how to get that to work, sorry)" from the
README.md file as it detracts from the professional tone of the documentation.
Simply delete this entire line to maintain a more polished and professional
appearance in the user-facing documentation.

---

Outside diff comments:
In `@src/Refitter.SourceGenerator/README.md`:
- Around line 62-64: The `.refitter` example in the README has invalid JSON
syntax where the outputFolder property is missing a trailing comma after the
value. Add a comma immediately after the outputFolder value (after the closing
quote of "../CustomOutput") to make the JSON valid and ready for copy/paste use.
The comment about the optional default can remain on the same line after the
comma.
- Line 63: The README.md documentation incorrectly states that the default
outputFilename is "Output.cs" (at line 63) and likely has the same outdated
information at line 191, but the actual implementation in
RefitterSourceGenerator.cs defaults to "<refitter-name>.g.cs". Update both
documentation locations in the README to correctly reflect the actual default
value used by the generator, replacing references to "Output.cs" or incorrect
defaults with the correct pattern "<refitter-name>.g.cs" to ensure users have
accurate configuration information.

---

Nitpick comments:
In `@src/Refitter.SourceGenerator.Tests/SourceGeneratorFileIOTests.cs`:
- Line 40: Rename the public test methods in SourceGeneratorFileIOTests.cs from
snake_case to PascalCase to comply with C# naming conventions. At line 40,
rename Test_CoreGenerator_DoesNotWriteToFileSystem to
TestCoreGeneratorDoesNotWriteToFileSystem. At line 67, rename the test method
there to PascalCase (removing underscores). At line 92, rename the test method
there to PascalCase (removing underscores). At line 114, rename the test method
there to PascalCase (removing underscores). Ensure all public test method names
follow PascalCase convention without underscores as separators.
🪄 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: 513e2f4d-06e1-4a54-8ac2-081834f199e3

📥 Commits

Reviewing files that changed from the base of the PR and between 029160d and c101318.

⛔ Files ignored due to path filters (9)
  • src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/.g.cs is excluded by !**/generated/**
  • src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/PropertyNamingPolicy.g.cs is excluded by !**/generated/**
  • src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/SwaggerPetstoreMultipleInterfaces.g.cs is excluded by !**/generated/**
  • src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/SwaggerPetstoreMultipleInterfacesByTag.g.cs is excluded by !**/generated/**
  • src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/SwaggerPetstoreOptionalParameters.g.cs is excluded by !**/generated/**
  • src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/SwaggerPetstoreSingleInterfaceWithHttpResilience.g.cs is excluded by !**/generated/**
  • src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/SwaggerPetstoreSingleInterfaceWithPolly.g.cs is excluded by !**/generated/**
  • src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/UseJsonInheritanceConverter.g.cs is excluded by !**/generated/**
  • src/Refitter.SourceGenerator.Tests/AdditionalFiles/Generated/UsePolymorphicSerialization.g.cs is excluded by !**/generated/**
📒 Files selected for processing (5)
  • src/Refitter.SourceGenerator.Tests/CustomGenerated/CustomGenerated.cs
  • src/Refitter.SourceGenerator.Tests/SourceGeneratorFileIOTests.cs
  • src/Refitter.SourceGenerator/README.md
  • src/Refitter.SourceGenerator/RefitterSourceGenerator.cs
  • test/SourceGenerator/Directory.Build.props

Comment thread src/Refitter.SourceGenerator/README.md
@codecov

codecov Bot commented Jun 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.31%. Comparing base (2825265) to head (c101318).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1143   +/-   ##
=======================================
  Coverage   94.31%   94.31%           
=======================================
  Files          48       48           
  Lines        2796     2796           
=======================================
  Hits         2637     2637           
  Misses         53       53           
  Partials      106      106           
Flag Coverage Δ
unittests 94.31% <ø> (ø)

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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant