RefitGenerator into separate modules (document filter, schema cleaner, code generator, pipeline) - #1146
Conversation
Pure functions that clone the document, filter, and return a new document.
…ator, RefitCodeGenerator
…or to thin facade
…itCodeGenerator, RefitPipeline
|
Warning Review limit reached
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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthrough
ChangesRefitGenerator decomposition
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (11)
src/Refitter.Core/IRefitCodeGenerator.cssrc/Refitter.Core/IRefitSchemaCleaner.cssrc/Refitter.Core/RefitCodeGenerator.cssrc/Refitter.Core/RefitDocumentFilter.cssrc/Refitter.Core/RefitGenerator.cssrc/Refitter.Core/RefitPipeline.cssrc/Refitter.Core/RefitSchemaCleaner.cssrc/Refitter.Tests/RefitCodeGeneratorTests.cssrc/Refitter.Tests/RefitDocumentFilterTests.cssrc/Refitter.Tests/RefitPipelineTests.cssrc/Refitter.Tests/RefitSchemaCleanerTests.cs
Codecov Report❌ Patch coverage is
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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. Fixes Applied SuccessfullyFixed 7 file(s) based on 6 unresolved review comments. Files modified:
Commit: The changes have been pushed to the Time taken: |
Fixed 7 file(s) based on 6 unresolved review comments. Co-authored-by: CodeRabbit <noreply@coderabbit.ai>
|



Description:
Fixes a build error in
src/Refitter.Core/RefitDocumentFilter.cscaused by a missingusing System.Text.RegularExpressions;directive. TheFilterByPathmethod usesRegexandRegexOptionswhich require this namespace import.The missing directive produced the following compiler errors:
CS0246: The type or namespace name 'Regex' could not be foundCS0103: The name 'RegexOptions' does not exist in the current contextAdding the missing using directive resolves both errors and restores a clean build.
Summary by CodeRabbit
New Features
Refactor
Tests