Skip to content

RefitGenerator into separate modules (document filter, schema cleaner, code generator, pipeline) - #1146

Merged
christianhelle merged 7 commits into
mainfrom
feat/deepen-refit-generator
Jun 14, 2026
Merged

RefitGenerator into separate modules (document filter, schema cleaner, code generator, pipeline)#1146
christianhelle merged 7 commits into
mainfrom
feat/deepen-refit-generator

Conversation

@christianhelle

@christianhelle christianhelle commented Jun 14, 2026

Copy link
Copy Markdown
Owner

Description:

Fixes a build error in src/Refitter.Core/RefitDocumentFilter.cs caused by a missing using System.Text.RegularExpressions; directive. The FilterByPath method uses Regex and RegexOptions which require this namespace import.

The missing directive produced the following compiler errors:

  • CS0246: The type or namespace name 'Regex' could not be found
  • CS0103: The name 'RegexOptions' does not exist in the current context

Adding the missing using directive resolves both errors and restores a clean build.

Summary by CodeRabbit

  • New Features

    • Added document filtering by operation tags and path patterns.
    • Added schema cleanup to remove unused schemas from generated code.
  • Refactor

    • Reorganized code generation architecture with dedicated pipeline orchestration.
  • Tests

    • Added comprehensive test coverage for document filtering, schema cleanup, and code generation.

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

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@coderabbitai[bot], we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 10 minutes and 29 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ed4a578e-3f82-4963-b0a3-e4d469ed58d9

📥 Commits

Reviewing files that changed from the base of the PR and between 0b8dae1 and b41e0ad.

📒 Files selected for processing (7)
  • src/Refitter.Core/RefitDocumentFilter.cs
  • src/Refitter.Core/RefitPipeline.cs
  • src/Refitter.Core/RefitSchemaCleaner.cs
  • src/Refitter.Tests/RefitCodeGeneratorTests.cs
  • src/Refitter.Tests/RefitDocumentFilterTests.cs
  • src/Refitter.Tests/RefitPipelineTests.cs
  • src/Refitter.Tests/RefitSchemaCleanerTests.cs
📝 Walkthrough

Walkthrough

RefitGenerator is decomposed from a monolithic class into a layered architecture. Two new interfaces (IRefitCodeGenerator, IRefitSchemaCleaner) are introduced alongside their implementations (RefitCodeGenerator, RefitSchemaCleaner), a new RefitDocumentFilter utility, and a RefitPipeline orchestrator. RefitGenerator becomes a thin facade delegating to these components. Tests are added for all new classes.

Changes

RefitGenerator decomposition

Layer / File(s) Summary
Public contracts
src/Refitter.Core/IRefitCodeGenerator.cs, src/Refitter.Core/IRefitSchemaCleaner.cs
Introduces IRefitCodeGenerator with Generate/GenerateMultipleFiles methods and IRefitSchemaCleaner with a non-mutating Clean method, both accepting OpenApiDocument.
Document filter and schema cleaner
src/Refitter.Core/RefitDocumentFilter.cs, src/Refitter.Core/RefitSchemaCleaner.cs, src/Refitter.Tests/RefitDocumentFilterTests.cs, src/Refitter.Tests/RefitSchemaCleanerTests.cs
Adds RefitDocumentFilter with FilterByTags and FilterByPath (regex-based, JSON-clone isolation) and RefitSchemaCleaner (NSwag-backed unused schema removal with keep patterns and inheritance inclusion). Tests cover empty inputs, filtering correctness, multi-pattern matching, and non-mutation of the original document.
RefitCodeGenerator implementation
src/Refitter.Core/RefitCodeGenerator.cs, src/Refitter.Tests/RefitCodeGeneratorTests.cs
Implements IRefitCodeGenerator as a sealed class: builds a GeneratorPipeline, formats single-file or multi-file output conditionally including interfaces, contracts, serializer context, DI code, and optional contract type suffix. Tests cover basic generation, tag-filtered output, compilation, and multi-file output shape.
Pipeline orchestration and RefitGenerator facade
src/Refitter.Core/RefitPipeline.cs, src/Refitter.Core/RefitGenerator.cs, src/Refitter.Tests/RefitPipelineTests.cs
RefitPipeline chains FilterByTags → FilterByPath → SchemaCleaner → RefitGenerator construction in Create, and loads OpenApiDocument asynchronously in CreateAsync. RefitGenerator is reduced to a facade delegating Create/CreateAsync to RefitPipeline and Generate/GenerateMultipleFiles to a static RefitCodeGenerator instance. Tests validate filtering, non-mutation, code output, and multi-file generation.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant RefitPipeline
  participant RefitDocumentFilter
  participant RefitSchemaCleaner
  participant RefitGenerator
  participant RefitCodeGenerator

  rect rgba(70, 130, 180, 0.5)
    note over Caller, RefitGenerator: Document loading and processing
    Caller->>RefitPipeline: CreateAsync(settings)
    RefitPipeline->>RefitPipeline: GetOpenApiDocument(settings)
    RefitPipeline->>RefitDocumentFilter: FilterByTags(document, includeTags)
    RefitDocumentFilter-->>RefitPipeline: filtered document (JSON clone)
    RefitPipeline->>RefitDocumentFilter: FilterByPath(document, includePathMatches)
    RefitDocumentFilter-->>RefitPipeline: filtered document (JSON clone)
    RefitPipeline->>RefitSchemaCleaner: Clean(document, removeUnused, keepPatterns, ...)
    RefitSchemaCleaner-->>RefitPipeline: cleaned document (JSON clone)
    RefitPipeline-->>Caller: RefitGenerator instance
  end

  rect rgba(60, 179, 113, 0.5)
    note over Caller, RefitCodeGenerator: Code generation
    Caller->>RefitGenerator: Generate()
    RefitGenerator->>RefitCodeGenerator: Generate(document, settings)
    RefitCodeGenerator->>RefitCodeGenerator: RunGeneratorPipeline(document, settings)
    RefitCodeGenerator-->>Caller: generated C# string
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • christianhelle/refitter#1127: Extracted GeneratorPipeline out of RefitGenerator to centralize orchestration, which is the direct predecessor to this PR's further decomposition into RefitPipeline, RefitCodeGenerator, and filter/cleaner components.
  • christianhelle/refitter#1131: Modified RefitGenerator.Create(...) and CreateAsync(...) to delegate through a new initialization/filtering flow, directly overlapping with this PR's rerouting of those same methods to RefitPipeline.
  • christianhelle/refitter#1067: Changed output composition in Generate/GenerateMultipleFiles (serializer context, multi-file assembly), which is the same code now extracted into RefitCodeGenerator in this PR.

Poem

🐇 Hop, hop, the monolith's split in two,
Pipeline and filter each have their queue,
Schemas get cleaned with a JSON clone trick,
Facades now delegate, light as a stick,
The rabbit refactors — the tests all agree,
Clean separation sets generated code free! ✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.27% 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: refactoring RefitGenerator into separate, independently testable modules (document filter, schema cleaner, code generator, pipeline).
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 unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/deepen-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.

@christianhelle christianhelle changed the title feat: deepen RefitGenerator into separate modules (document filter, schema cleaner, code generator, pipeline) Refactor RefitGenerator into separate modules (document filter, schema cleaner, code generator, pipeline) Jun 14, 2026
Copilot AI changed the title Refactor RefitGenerator into separate modules (document filter, schema cleaner, code generator, pipeline) Fix build error: add missing using directive in RefitDocumentFilter Jun 14, 2026
@christianhelle christianhelle changed the title Fix build error: add missing using directive in RefitDocumentFilter RefitGenerator into separate modules (document filter, schema cleaner, code generator, pipeline) Jun 14, 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: 6

🤖 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/RefitDocumentFilter.cs`:
- Around line 20-23: Add explicit null argument validation at the beginning of
the public filter methods to ensure clear contract exceptions instead of generic
NullReferenceExceptions. In the FilterByTags method, add null checks for both
the document and includeTags parameters before they are dereferenced. Similarly,
apply the same validation pattern to the other filter method around line 63-66
for its document and includePathMatches parameters. Use ArgumentNullException to
throw descriptive exceptions when null arguments are passed, ensuring the
validation occurs before any parameter usage.

In `@src/Refitter.Core/RefitPipeline.cs`:
- Around line 42-60: The CreateAsync method does not validate that the settings
parameter is null before passing it to GetOpenApiDocument, which will cause a
NullReferenceException when GetOpenApiDocument tries to dereference
settings.OpenApiPaths or settings.OpenApiPath. Add a null guard at the start of
CreateAsync that throws ArgumentNullException if settings is null, ensuring the
method fails fast with a clear error message consistent with the Create method's
behavior.

In `@src/Refitter.Core/RefitSchemaCleaner.cs`:
- Around line 19-29: Add explicit null argument validation at the beginning of
the Clean method for both the document and keepSchemaPatterns parameters. Before
any logic executes, check if document is null and throw an ArgumentNullException
with an appropriate message. Similarly, check if keepSchemaPatterns is null and
throw an ArgumentNullException. This ensures callers receive deterministic
failures immediately with clear error messages rather than encountering failures
later in the CloneDocument call or SchemaCleaner constructor invocation.

In `@src/Refitter.Tests/RefitCodeGeneratorTests.cs`:
- Around line 12-32: The test coverage for OpenAPI specifications is incomplete
as it only validates OpenAPI 3.0 behavior. In
src/Refitter.Tests/RefitCodeGeneratorTests.cs (lines 12-32), add a new
Swagger/OpenAPI 2.0 constant fixture similar to the OpenApiSpec constant and
then run equivalent test assertions for the Generate and GenerateMultipleFiles
methods using this 2.0 fixture. In src/Refitter.Tests/RefitPipelineTests.cs
(lines 11-38), add a separate Swagger/OpenAPI 2.0 constant fixture and mirror
the key pipeline assertion logic including filtering, generation validation, and
non-empty output verification using this 2.0 fixture. This ensures both test
suites validate OpenAPI 2.0 behavior in addition to the existing 3.0 coverage.

In `@src/Refitter.Tests/RefitDocumentFilterTests.cs`:
- Around line 10-51: The RefitDocumentFilterTests class currently only exercises
filter behavior with an OpenAPI 3.0 specification. To comply with testing
guidelines requiring coverage of both supported spec versions, add a new private
const string field for an OpenAPI 2.0 (Swagger) specification with the same
endpoint structure as the existing OpenApiSpec constant, then add parallel test
assertions or test methods that validate the filter behavior works identically
with the OpenAPI 2.0 document to ensure filters function correctly across both
specification versions.

In `@src/Refitter.Tests/RefitSchemaCleanerTests.cs`:
- Around line 13-168: The test class RefitSchemaCleanerTests currently only
validates OpenAPI 3.0 specifications. Add OpenAPI 2.0 test variants for each of
the four existing test methods:
Clean_WithRemoveUnusedSchemaFalse_KeepsAllSchemas,
Clean_WithRemoveUnusedSchemaTrue_RemovesUnusedSchemas,
Clean_DoesNotMutateOriginalDocument, and Clean_KeepsSchemasMatchingKeepPattern.
For each 2.0 variant, convert the OpenAPI 3.0 YAML specification (which uses
openapi: '3.0.0' and 3.0-style schema references) to OpenAPI 2.0 format (using
swagger: '2.0' instead), adjust the path and response structures to match
Swagger 2.0 conventions, and verify that the RefitSchemaCleaner behaves
consistently across both specification versions. The assertions and test logic
should remain identical to their 3.0 counterparts.
🪄 Autofix (Beta)

✅ Autofix completed


ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 715aa15a-e61f-41ed-8cd9-e3a0bb043f93

📥 Commits

Reviewing files that changed from the base of the PR and between e819ceb and 0b8dae1.

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

Comment thread src/Refitter.Core/RefitDocumentFilter.cs
Comment thread src/Refitter.Core/RefitPipeline.cs
Comment thread src/Refitter.Core/RefitSchemaCleaner.cs
Comment thread src/Refitter.Tests/RefitCodeGeneratorTests.cs
Comment thread src/Refitter.Tests/RefitDocumentFilterTests.cs
Comment thread src/Refitter.Tests/RefitSchemaCleanerTests.cs
@codecov

codecov Bot commented Jun 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.62069% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.15%. Comparing base (25407ad) to head (b41e0ad).
⚠️ Report is 20 commits behind head on main.

Files with missing lines Patch % Lines
src/Refitter.Core/RefitDocumentFilter.cs 97.77% 0 Missing and 1 partial ⚠️
src/Refitter.Core/RefitGenerator.cs 80.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1146      +/-   ##
==========================================
- Coverage   94.31%   94.15%   -0.17%     
==========================================
  Files          48       59      +11     
  Lines        2796     2890      +94     
==========================================
+ Hits         2637     2721      +84     
- Misses         53       59       +6     
- Partials      106      110       +4     
Flag Coverage Δ
unittests 94.15% <98.62%> (-0.17%) ⬇️

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.

@coderabbitai

coderabbitai Bot commented Jun 14, 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 7 file(s) based on 6 unresolved review comments.

Files modified:

  • src/Refitter.Core/RefitDocumentFilter.cs
  • src/Refitter.Core/RefitPipeline.cs
  • src/Refitter.Core/RefitSchemaCleaner.cs
  • src/Refitter.Tests/RefitCodeGeneratorTests.cs
  • src/Refitter.Tests/RefitDocumentFilterTests.cs
  • src/Refitter.Tests/RefitPipelineTests.cs
  • src/Refitter.Tests/RefitSchemaCleanerTests.cs

Commit: b41e0ad52afc3ad8191196cf189ca94bb34df9f1

The changes have been pushed to the feat/deepen-refit-generator branch.

Time taken: 4m 51s

@christianhelle
christianhelle enabled auto-merge June 14, 2026 23:26
Fixed 7 file(s) based on 6 unresolved review comments.

Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
@christianhelle
christianhelle merged commit d69ce5d into main Jun 14, 2026
9 of 10 checks passed
@christianhelle
christianhelle deleted the feat/deepen-refit-generator branch June 14, 2026 23:32
@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.

2 participants