[repo-assist] refactor: extract tryResolveSingle helper in DefinitionCompiler#441
Merged
sergey-tihon merged 2 commits intoMay 17, 2026
Conversation
The resolvedType block had three near-identical if/else branches for AllOf, OneOf, and AnyOf, each of which checked the collection for a single non-null inline subschema and returned its type. Extract a shared helper and rewrite the block using Option.orElseWith chaining: - Eliminates ~25 lines of duplicate if/else logic - Checks schemaObj.Type.HasValue first (most common case) - Helper handles both null collection and missing-type cases No functional change; all 417 unit tests continue to pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors triplicated if/else logic in DefinitionCompiler.compileBySchema that resolved a single inline subschema type from AllOf/OneOf/AnyOf into a shared tryResolveSingle helper, and uses Option.orElseWith chaining. Behavior is preserved (Type.HasValue still takes precedence).
Changes:
- Extract
tryResolveSinglelocal helper for single-subschema type resolution. - Replace nested
if/elsechain withOption.orElseWithpipeline. - Check
schemaObj.Type.HasValuefirst as the common-case fast path.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This was referenced May 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This PR was created by Repo Assist, an automated AI assistant.
Summary
The
resolvedTypeblock inDefinitionCompiler.compileBySchemahad three near-identicalif/elsebranches — one each forAllOf,OneOf, andAnyOf— that each checked for a single non-null inline subschema and returned itsType. This PR extracts a sharedtryResolveSinglehelper and rewrites the block usingOption.orElseWithchaining.Before
After
Benefits
schemaObj.Type.HasValuefirst (the most common case)Option.orElseWithchain makes the short-circuit logic explicitTest Status
No functional change. All 417 unit tests continue to pass.