Skip to content

Revert "Refactor Refit Generator"#1153

Closed
christianhelle wants to merge 1 commit into
mainfrom
revert-1151-refactor-refit-generator
Closed

Revert "Refactor Refit Generator"#1153
christianhelle wants to merge 1 commit into
mainfrom
revert-1151-refactor-refit-generator

Conversation

@christianhelle

@christianhelle christianhelle commented Jun 16, 2026

Copy link
Copy Markdown
Owner

Reverts #1151

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a streamlined code generation pipeline for improved modularity and flexibility.
    • Added schema cleaning capabilities to automatically remove unused schemas from OpenAPI documents.
  • Refactor

    • Restructured code generation workflow to separate concerns and enhance maintainability.
  • Tests

    • Expanded test coverage for the new pipeline and schema cleaning functionality.

@coderabbitai

coderabbitai Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Extracts OpenAPI document loading, tag/path filtering, and schema cleaning from RefitGenerator into a new RefitPipeline static class and a RefitSchemaCleaner implementation. Introduces two new public interfaces (IRefitCodeGenerator, IRefitSchemaCleaner), makes RefitCodeGenerator public, and reduces RefitGenerator to a thin facade. Tests are updated and new schema cleaner tests added.

Changes

Pipeline Architecture Refactor

Layer / File(s) Summary
Public interface contracts
src/Refitter.Core/IRefitCodeGenerator.cs, src/Refitter.Core/IRefitSchemaCleaner.cs
Adds IRefitCodeGenerator declaring Generate and GenerateMultipleFiles, and IRefitSchemaCleaner declaring Clean with non-mutation semantics documented in XML docs.
RefitSchemaCleaner implementation and tests
src/Refitter.Core/RefitSchemaCleaner.cs, src/Refitter.Tests/RefitSchemaCleanerTests.cs
Implements IRefitSchemaCleaner.Clean with input validation, bypass when removal is disabled, JSON round-trip cloning, and NSwag SchemaCleaner configuration. Tests cover OpenAPI 3.0 and Swagger 2.0 for disabled removal, enabled removal, non-mutation, and keep-pattern preservation.
RefitPipeline orchestration
src/Refitter.Core/RefitPipeline.cs
New static class orchestrating the full pipeline: synchronous Create validates, filters by tags/paths, cleans schemas, and returns a RefitGenerator; asynchronous CreateAsync loads documents via OpenApiDocumentFactory then delegates to Create.
RefitCodeGenerator public + RefitGenerator facade
src/Refitter.Core/RefitCodeGenerator.cs, src/Refitter.Core/RefitGenerator.cs
RefitCodeGenerator visibility changed from internal to public. RefitGenerator adds a synchronous Create factory, delegates CreateAsync to RefitPipeline.CreateAsync, and removes prior in-file loading/filtering/cleaning helpers.
RefitPipelineTests
src/Refitter.Tests/RefitPipelineTests.cs
Test class renamed from RefitGeneratorTests to RefitPipelineTests; all SUT creation switched to RefitPipeline; new Create_DoesNotMutateOriginalDocument test added; code-generation and multi-file tests retargeted to pipeline.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant RefitPipeline
  participant OpenApiDocumentFactory
  participant RefitSchemaCleaner
  participant RefitGenerator
  participant RefitCodeGenerator

  rect rgba(70, 130, 180, 0.5)
    note over Caller,RefitPipeline: Async path (file-based)
    Caller->>RefitPipeline: CreateAsync(settings)
    RefitPipeline->>OpenApiDocumentFactory: CreateAsync(OpenApiPath)
    OpenApiDocumentFactory-->>RefitPipeline: OpenApiDocument
  end

  rect rgba(100, 160, 100, 0.5)
    note over RefitPipeline,RefitGenerator: Sync pipeline (shared by both paths)
    RefitPipeline->>RefitPipeline: Create(document, settings)
    RefitPipeline->>RefitPipeline: FilterByTags(document, settings)
    RefitPipeline->>RefitPipeline: FilterByPath(document, settings)
    RefitPipeline->>RefitSchemaCleaner: Clean(document, removeUnusedSchema, keepPatterns, hierarchy)
    RefitSchemaCleaner-->>RefitPipeline: cleaned OpenApiDocument
    RefitPipeline->>RefitGenerator: new RefitGenerator(cleanedDocument, settings)
  end

  Caller->>RefitGenerator: Generate() / GenerateMultipleFiles()
  RefitGenerator->>RefitCodeGenerator: Generate(document, settings)
  RefitCodeGenerator-->>Caller: string / GeneratorOutput
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • christianhelle/refitter#1151: Directly reverses/removes the same IRefitCodeGenerator, IRefitSchemaCleaner, RefitPipeline, and RefitSchemaCleaner additions introduced by this PR.
  • christianhelle/refitter#1146: Introduces the same modular extraction — IRefitCodeGenerator, IRefitSchemaCleaner, RefitSchemaCleaner, and RefitPipeline — that this PR implements, with RefitGenerator becoming a facade.
  • christianhelle/refitter#1079: Modifies the same GetOpenApiDocument validation path that this PR relocates from RefitGenerator into RefitPipeline.

Suggested labels

enhancement, .NET

🐇 A pipeline now cleans the schema with care,
No mutation sneaks in — the original's spare!
RefitPipeline leads, the facade stands thin,
The cleaner chops schemas — unused, begone! — with a grin.
Code flows through the stages, as tidy as can be. 🌿

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Title check ⚠️ Warning The PR title claims to revert a previous refactor, but the changes actually add new public interfaces and classes that didn't exist before. Update the title to accurately reflect the actual changes, such as 'Extract refactored generator pipeline into public interfaces' or 'Introduce RefitPipeline and schema cleaner abstractions'.
Docstring Coverage ⚠️ Warning Docstring coverage is 32.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.
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 revert-1151-refactor-refit-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 (1)
src/Refitter.Tests/RefitPipelineTests.cs (1)

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

Add compile verification for generated code paths.

These tests validate content/non-empty output but do not verify that generated code actually compiles. Please add BuildHelper.BuildCSharp() assertions (including targetFramework coverage for net8.0, net9.0, and net10.0) for the generated outputs in these methods.

As per coding guidelines, tests must use BuildHelper.BuildCSharp() to verify generated code compiles, supporting net8.0, net9.0, and net10.0 via the targetFramework parameter.

Also applies to: 144-160, 182-196

🤖 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/RefitPipelineTests.cs` around lines 127 - 141, The
Pipeline_Generate_ProducesValidCode method generates code but only validates
that the output is non-empty and contains expected strings, without verifying
that the generated code actually compiles. Add BuildHelper.BuildCSharp()
assertions after the generatedCode variable is set to verify compilation
success, testing across three target frameworks: net8.0, net9.0, and net10.0
using the targetFramework parameter. Apply this same fix to the other similar
test methods mentioned in the comment (the ones at lines 144-160 and 182-196) to
ensure all generated code paths are verified to compile across all supported
frameworks.

Source: Coding guidelines

🧹 Nitpick comments (5)
src/Refitter.Core/RefitPipeline.cs (2)

25-26: 💤 Low value

Replace var with explicit types.

As per coding guidelines, the use of var keyword is discouraged. Use explicit types instead.

♻️ Suggested fix
-        var processed = RefitDocumentFilter.FilterByTags(document, settings.IncludeTags);
-        processed = RefitDocumentFilter.FilterByPath(processed, settings.IncludePathMatches);
+        OpenApiDocument processed = RefitDocumentFilter.FilterByTags(document, settings.IncludeTags);
+        processed = RefitDocumentFilter.FilterByPath(processed, settings.IncludePathMatches);

And on line 46:

-        var openApiDocument = await GetOpenApiDocument(settings).ConfigureAwait(false);
+        OpenApiDocument openApiDocument = await GetOpenApiDocument(settings).ConfigureAwait(false);

Also applies to: 46-46

🤖 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.Core/RefitPipeline.cs` around lines 25 - 26, Replace the `var`
keyword with explicit types in the RefitPipeline class. For the `processed`
variable assignments that result from calling RefitDocumentFilter.FilterByTags()
and RefitDocumentFilter.FilterByPath(), declare the variable with its explicit
return type instead of using `var`. Identify the actual return type from these
filter methods and use that type annotation for the variable declaration.

Source: Coding guidelines


11-11: ⚡ Quick win

Private static fields should use camelCase per coding guidelines.

Both files define private static readonly fields using PascalCase, which violates the guideline requiring camelCase without underscore prefix for private fields.

  • src/Refitter.Core/RefitPipeline.cs#L11-L11: Rename SchemaCleaner to schemaCleaner and update references on lines 27-31.
  • src/Refitter.Core/RefitGenerator.cs#L11-L11: Rename CodeGenerator to codeGenerator and update references on lines 36 and 42.
🤖 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.Core/RefitPipeline.cs` at line 11, Private static fields must
follow camelCase naming convention without underscore prefix. In
src/Refitter.Core/RefitPipeline.cs at line 11, rename the static field
SchemaCleaner to schemaCleaner and update all references to this field on lines
27-31 to use the new camelCase name. In src/Refitter.Core/RefitGenerator.cs at
line 11, rename the static field CodeGenerator to codeGenerator and update all
references to this field on lines 36 and 42 to use the new camelCase name.

Source: Coding guidelines

src/Refitter.Core/RefitSchemaCleaner.cs (1)

31-32: ⚡ Quick win

Use explicit local types instead of var in core cleaner logic.

Please replace var with explicit types for result and cleaner to match repository C# style guidance.

As per coding guidelines, "**/*.cs: Discourage the use of var keyword; use explicit types instead."

🤖 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.Core/RefitSchemaCleaner.cs` around lines 31 - 32, Replace the
`var` keyword with explicit types in the RefitSchemaCleaner.cs file to comply
with repository C# style guidance. For the `result` variable assigned from the
CloneDocument method call, use the explicit return type of CloneDocument. For
the `cleaner` variable assigned from the SchemaCleaner constructor, use the
explicit type SchemaCleaner instead of var for both declarations.

Source: Coding guidelines

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

36-40: ⚡ Quick win

Tests follow TUnit and OpenAPI 2.0/3.0 coverage, but local typing should be explicit.

Please replace repeated var declarations with explicit types in this test class to conform to project C# conventions.

As per coding guidelines, "**/*.cs: Discourage the use of var keyword; use explicit types instead."

Also applies to: 75-80, 115-121, 159-164, 197-202, 235-240, 274-280, 317-322

🤖 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/RefitSchemaCleanerTests.cs` around lines 36 - 40, Replace
all var keyword declarations with explicit types throughout the
RefitSchemaCleanerTests.cs test class to conform to project C# conventions. In
the test method shown, replace var with explicit types for variables like json
(OpenApiYamlDocument), document (OpenApiDocument), sut (RefitSchemaCleaner), and
result (infer the return type from the Clean method). Apply the same pattern
consistently across all test methods in this class, declaring variables with
their actual types instead of using var.

Source: Coding guidelines

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

82-82: ⚡ Quick win

Replace var with explicit types in changed declarations.

var is used in multiple changed lines (for example, Line 82 and Line 136). Please switch these to explicit types for consistency with repository C# conventions.

As per coding guidelines, var is discouraged in **/*.cs files and explicit types should be used.

Also applies to: 94-94, 101-101, 113-114, 136-136, 156-156, 173-173, 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.Tests/RefitPipelineTests.cs` at line 82, Replace all instances
of `var` declarations with explicit types in the RefitPipelineTests.cs file to
comply with repository C# conventions. Specifically, identify each `var` keyword
used in variable declarations (such as the `sut` variable assigned from
RefitPipeline.CreateAsync() at the anchor location, and the other locations
mentioned in the comment) and replace it with the appropriate explicit type.
Determine the correct type for each variable by examining its assignment and use
the fully qualified type name where necessary.

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.Core/IRefitSchemaCleaner.cs`:
- Around line 5-8: The documentation for the Clean method in IRefitSchemaCleaner
interface claims to return a new document, but the actual implementation in
RefitSchemaCleaner.Clean returns the original document instance when
removeUnusedSchema is false. Update the XML documentation summary comment at
IRefitSchemaCleaner (lines 5-8) to clarify that the method returns a
non-mutating result that does not modify the input document, rather than
guaranteeing a new instance. Apply the same documentation update to the
RefitSchemaCleaner.Clean method implementation (lines 19-23) to maintain
consistency between the interface contract and implementation.

---

Outside diff comments:
In `@src/Refitter.Tests/RefitPipelineTests.cs`:
- Around line 127-141: The Pipeline_Generate_ProducesValidCode method generates
code but only validates that the output is non-empty and contains expected
strings, without verifying that the generated code actually compiles. Add
BuildHelper.BuildCSharp() assertions after the generatedCode variable is set to
verify compilation success, testing across three target frameworks: net8.0,
net9.0, and net10.0 using the targetFramework parameter. Apply this same fix to
the other similar test methods mentioned in the comment (the ones at lines
144-160 and 182-196) to ensure all generated code paths are verified to compile
across all supported frameworks.

---

Nitpick comments:
In `@src/Refitter.Core/RefitPipeline.cs`:
- Around line 25-26: Replace the `var` keyword with explicit types in the
RefitPipeline class. For the `processed` variable assignments that result from
calling RefitDocumentFilter.FilterByTags() and
RefitDocumentFilter.FilterByPath(), declare the variable with its explicit
return type instead of using `var`. Identify the actual return type from these
filter methods and use that type annotation for the variable declaration.
- Line 11: Private static fields must follow camelCase naming convention without
underscore prefix. In src/Refitter.Core/RefitPipeline.cs at line 11, rename the
static field SchemaCleaner to schemaCleaner and update all references to this
field on lines 27-31 to use the new camelCase name. In
src/Refitter.Core/RefitGenerator.cs at line 11, rename the static field
CodeGenerator to codeGenerator and update all references to this field on lines
36 and 42 to use the new camelCase name.

In `@src/Refitter.Core/RefitSchemaCleaner.cs`:
- Around line 31-32: Replace the `var` keyword with explicit types in the
RefitSchemaCleaner.cs file to comply with repository C# style guidance. For the
`result` variable assigned from the CloneDocument method call, use the explicit
return type of CloneDocument. For the `cleaner` variable assigned from the
SchemaCleaner constructor, use the explicit type SchemaCleaner instead of var
for both declarations.

In `@src/Refitter.Tests/RefitPipelineTests.cs`:
- Line 82: Replace all instances of `var` declarations with explicit types in
the RefitPipelineTests.cs file to comply with repository C# conventions.
Specifically, identify each `var` keyword used in variable declarations (such as
the `sut` variable assigned from RefitPipeline.CreateAsync() at the anchor
location, and the other locations mentioned in the comment) and replace it with
the appropriate explicit type. Determine the correct type for each variable by
examining its assignment and use the fully qualified type name where necessary.

In `@src/Refitter.Tests/RefitSchemaCleanerTests.cs`:
- Around line 36-40: Replace all var keyword declarations with explicit types
throughout the RefitSchemaCleanerTests.cs test class to conform to project C#
conventions. In the test method shown, replace var with explicit types for
variables like json (OpenApiYamlDocument), document (OpenApiDocument), sut
(RefitSchemaCleaner), and result (infer the return type from the Clean method).
Apply the same pattern consistently across all test methods in this class,
declaring variables with their actual types instead of using var.
🪄 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: bba9cb40-4ccd-405d-b996-79e346e4d286

📥 Commits

Reviewing files that changed from the base of the PR and between 441a76d and dd90ff1.

📒 Files selected for processing (8)
  • src/Refitter.Core/IRefitCodeGenerator.cs
  • src/Refitter.Core/IRefitSchemaCleaner.cs
  • src/Refitter.Core/RefitCodeGenerator.cs
  • src/Refitter.Core/RefitGenerator.cs
  • src/Refitter.Core/RefitPipeline.cs
  • src/Refitter.Core/RefitSchemaCleaner.cs
  • src/Refitter.Tests/RefitPipelineTests.cs
  • src/Refitter.Tests/RefitSchemaCleanerTests.cs

Comment on lines +5 to +8
/// <summary>
/// Cleans an OpenAPI document by removing unreferenced schemas.
/// Returns a new document without mutating the input.
/// </summary>

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Public contract says “new document,” but implementation can return the original instance.

The interface documentation currently guarantees a new instance, while RefitSchemaCleaner.Clean returns the original document when removeUnusedSchema is false. Please align this contract to “non-mutating” semantics (or change implementation to always clone).

Also applies to: 19-23

🤖 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.Core/IRefitSchemaCleaner.cs` around lines 5 - 8, The
documentation for the Clean method in IRefitSchemaCleaner interface claims to
return a new document, but the actual implementation in RefitSchemaCleaner.Clean
returns the original document instance when removeUnusedSchema is false. Update
the XML documentation summary comment at IRefitSchemaCleaner (lines 5-8) to
clarify that the method returns a non-mutating result that does not modify the
input document, rather than guaranteeing a new instance. Apply the same
documentation update to the RefitSchemaCleaner.Clean method implementation
(lines 19-23) to maintain consistency between the interface contract and
implementation.

@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.36842% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 94.54%. Comparing base (43d46b0) to head (dd90ff1).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
src/Refitter.Core/RefitGenerator.cs 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1153      +/-   ##
==========================================
- Coverage   94.57%   94.54%   -0.03%     
==========================================
  Files          65       67       +2     
  Lines        3095     3100       +5     
==========================================
+ Hits         2927     2931       +4     
- Misses         58       59       +1     
  Partials      110      110              
Flag Coverage Δ
unittests 94.54% <97.36%> (-0.03%) ⬇️

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant