Skip to content

[repo-assist] refactor: extract tryResolveSingle helper in DefinitionCompiler#441

Merged
sergey-tihon merged 2 commits into
masterfrom
repo-assist/refactor-definition-compiler-resolved-type-c406404cb258788a
May 17, 2026
Merged

[repo-assist] refactor: extract tryResolveSingle helper in DefinitionCompiler#441
sergey-tihon merged 2 commits into
masterfrom
repo-assist/refactor-definition-compiler-resolved-type-c406404cb258788a

Conversation

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This PR was created by Repo Assist, an automated AI assistant.

Summary

The resolvedType block in DefinitionCompiler.compileBySchema had three near-identical if/else branches — one each for AllOf, OneOf, and AnyOf — that each checked for a single non-null inline subschema and returned its Type. This PR extracts a shared tryResolveSingle helper and rewrites the block using Option.orElseWith chaining.

Before

let resolvedType =
    if not schemaObj.Type.HasValue && not(isNull schemaObj.AllOf) && schemaObj.AllOf.Count = 1 then
        let firstAllOf = schemaObj.AllOf.[0]
        if not(isNull firstAllOf) && firstAllOf.Type.HasValue then Some firstAllOf.Type.Value
        else None
    else if not schemaObj.Type.HasValue && not(isNull schemaObj.OneOf) && schemaObj.OneOf.Count = 1 then
        // ... identical pattern ...
    // ... and again for AnyOf ...
    else if schemaObj.Type.HasValue then
        Some schemaObj.Type.Value
    else
        None

After

let resolvedType =
    let tryResolveSingle(schemas: IList<IOpenApiSchema>) =
        if not(isNull schemas) && schemas.Count = 1 then
            let first = schemas.[0]
            if not(isNull first) && first.Type.HasValue then Some first.Type.Value else None
        else
            None
    if schemaObj.Type.HasValue then
        Some schemaObj.Type.Value
    else
        tryResolveSingle schemaObj.AllOf
        |> Option.orElseWith(fun () -> tryResolveSingle schemaObj.OneOf)
        |> Option.orElseWith(fun () -> tryResolveSingle schemaObj.AnyOf)

Benefits

  • Removes ~25 lines of duplicated logic
  • Checks schemaObj.Type.HasValue first (the most common case)
  • More readable: the Option.orElseWith chain makes the short-circuit logic explicit

Test Status

No functional change. All 417 unit tests continue to pass.

SwaggerProvider.Tests  Total: 417, Errors: 0, Failed: 0, Skipped: 1, Time: 1.022s

Generated by 🌈 Repo Assist, see workflow run. Learn more.

To install this agentic workflow, run

gh aw add githubnext/agentics/workflows/repo-assist.md@79c99dfd73f3b7ad8ab2b0f4944838018dbe4736

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>
@sergey-tihon sergey-tihon marked this pull request as ready for review May 17, 2026 21:16
Copilot AI review requested due to automatic review settings May 17, 2026 21:16
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 tryResolveSingle local helper for single-subschema type resolution.
  • Replace nested if/else chain with Option.orElseWith pipeline.
  • Check schemaObj.Type.HasValue first as the common-case fast path.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@sergey-tihon sergey-tihon merged commit d07140f into master May 17, 2026
6 checks passed
@sergey-tihon sergey-tihon deleted the repo-assist/refactor-definition-compiler-resolved-type-c406404cb258788a branch May 17, 2026 21:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants