@@ -150,7 +150,7 @@ and NamespaceAbstraction(name: string) =
150150 Some ty)
151151
152152/// Object for compiling definitions.
153- type DefinitionCompiler ( schema : SwaggerObject , provideNullable ) as this =
153+ type DefinitionCompiler ( schema : SwaggerObject , provideNullable , useDateOnly : bool ) as this =
154154 let definitionToSchemaObject = Map.ofSeq schema.Definitions
155155 let definitionToType = Collections.Generic.Dictionary<_, _>()
156156 let nsRoot = NamespaceAbstraction( " Root" )
@@ -353,11 +353,15 @@ type DefinitionCompiler(schema: SwaggerObject, provideNullable) as this =
353353 | Double -> typeof< double>
354354 | String -> typeof< string>
355355 | Date ->
356- // Runtime detection: design-time assembly targets netstandard2.0 so
357- // compile-time NET6_0_OR_GREATER is not available; DateOnly exists on .NET 6+
358- System.Type.GetType( " System.DateOnly" )
359- |> Option.ofObj
360- |> Option.defaultValue typeof< DateTime>
356+ // Use DateOnly only when the target runtime supports it (.NET 6+).
357+ // We check useDateOnly (derived from cfg.SystemRuntimeAssemblyVersion) rather than
358+ // probing the design-time host process, which may differ from the consumer's runtime.
359+ if useDateOnly then
360+ System.Type.GetType( " System.DateOnly" )
361+ |> Option.ofObj
362+ |> Option.defaultValue typeof< DateTime>
363+ else
364+ typeof< DateTime>
361365 | DateTime -> typeof< DateTime>
362366 | File -> typeof< byte>. MakeArrayType 1
363367 | Enum(_, " string" ) -> typeof< string>
0 commit comments