Skip to content

Commit f32ae75

Browse files
authored
feat: Handle allOf with single reference (#284)
* feat: treat null as a object * feat: add immich schema test case * feat: explicitly handle allOf with single reference
1 parent 2c67ab2 commit f32ae75

File tree

4 files changed

+23484
-0
lines changed

4 files changed

+23484
-0
lines changed

src/SwaggerProvider.DesignTime/v3/DefinitionCompiler.fs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,21 @@ type DefinitionCompiler(schema: OpenApiDocument, provideNullable) as this =
443443
compileBySchema ns (ns.ReserveUniqueName tyName "Item") elSchema true ns.RegisterType false
444444

445445
ProvidedTypeBuilder.MakeGenericType(typedefof<Map<string, obj>>, [ typeof<string>; elTy ])
446+
// Handle allOf with single reference (e.g., nullable reference to another type)
447+
| _ when
448+
not(isNull schemaObj.AllOf)
449+
&& schemaObj.AllOf.Count = 1
450+
&& (schemaObj.Properties |> isNull || schemaObj.Properties.Count = 0)
451+
->
452+
match schemaObj.AllOf.[0] with
453+
| :? OpenApiSchemaReference as schemaRef when not(isNull schemaRef.Reference) ->
454+
ns.ReleaseNameReservation tyName
455+
compileByPath <| getFullPath schemaRef.Reference.Id
456+
| _ -> compileNewObject()
446457
| _ when
447458
resolvedType.IsNone
448459
|| resolvedType = Some JsonSchemaType.Object
460+
|| resolvedType = Some JsonSchemaType.Null
449461
|| resolvedType = Some(JsonSchemaType.Null ||| JsonSchemaType.Object)
450462
->
451463
compileNewObject()

0 commit comments

Comments
 (0)