From e1090d9ebaa88cb32e0de6de3a5f1461a662a632 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 17 May 2026 20:03:48 +0000 Subject: [PATCH 1/2] refactor: extract tryResolveSingle helper in DefinitionCompiler 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> --- .../DefinitionCompiler.fs | 42 +++++-------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/src/SwaggerProvider.DesignTime/DefinitionCompiler.fs b/src/SwaggerProvider.DesignTime/DefinitionCompiler.fs index 4349c80e..24c4dca2 100644 --- a/src/SwaggerProvider.DesignTime/DefinitionCompiler.fs +++ b/src/SwaggerProvider.DesignTime/DefinitionCompiler.fs @@ -411,43 +411,23 @@ type DefinitionCompiler(schema: OpenApiDocument, provideNullable, useDateOnly: b let resolvedType = // If schemaObj.Type is missing, but allOf/oneOf/anyOf is present with one subschema, use that - 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 - let firstOneOf = schemaObj.OneOf.[0] + let tryResolveSingle(schemas: System.Collections.Generic.IList) = + if not(isNull schemas) && schemas.Count = 1 then + let first = schemas.[0] - if not(isNull firstOneOf) && firstOneOf.Type.HasValue then - Some firstOneOf.Type.Value + if not(isNull first) && first.Type.HasValue then + Some first.Type.Value + else + None else None - else if - not schemaObj.Type.HasValue - && not(isNull schemaObj.AnyOf) - && schemaObj.AnyOf.Count = 1 - then - let firstAnyOf = schemaObj.AnyOf.[0] - if not(isNull firstAnyOf) && firstAnyOf.Type.HasValue then - Some firstAnyOf.Type.Value - else - None - else if schemaObj.Type.HasValue then + if schemaObj.Type.HasValue then Some schemaObj.Type.Value else - None + tryResolveSingle schemaObj.AllOf + |> Option.orElseWith(fun () -> tryResolveSingle schemaObj.OneOf) + |> Option.orElseWith(fun () -> tryResolveSingle schemaObj.AnyOf) // Helper to get full definition path from reference ID let getFullPath(refId: string) = From c3528e59c69901ed258d61569bc078b3db89b3fd Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 17 May 2026 20:03:51 +0000 Subject: [PATCH 2/2] ci: trigger checks