Skip to content

Cannot deserialise null date #286

@malacandrian

Description

@malacandrian

When using the OpenApiProvider with the Immich API, it cannot deserialise PersonResponseDtos if their birthdate has not been set.

Reproduction Steps

  1. Get API key for the immich api demo from https://api.immich.app/endpoints/api-keys/getApiKeys
  2. Run the below script
#r "nuget: SwaggerProvider, 3.0.0-beta04"
open SwaggerProvider
open System
open System.Net.Http

let  [<Literal>] private Schema = "https://raw.githubusercontent.com/immich-app/immich/refs/heads/main/open-api/immich-openapi-specs.json"
type Api = OpenApiClientProvider<Schema>

let httpClient = new HttpClient()
httpClient.BaseAddress <- URI "https://demo.immich.app/api/"
httpClient.DefaultRequestHeaders.Add ("x-api-key", "{Key from step 1}")
let apiClient = Api.Client httpClient

apiClient.GetAllPeople()
|> Async.AwaitTask
|> Async.RunSynchronously

Result

The following exception is raised

Error: System.AggregateException: One or more errors occurred. (The JSON value could not be converted to System.DateTimeOffset. Path: $.people[0].birthDate | LineNumber: 0 | BytePositionInLine: 86.)
---> System.Text.Json.JsonException: The JSON value could not be converted to System.DateTimeOffset. Path: $.people[0].birthDate | LineNumber: 0 | BytePositionInLine: 86.
---> System.InvalidOperationException: Cannot get the value of a token type 'Null' as a string.Error: System.AggregateException: One or more errors occurred. (The JSON value could not be converted to System.DateTimeOffset. Path: $.people[0].birthDate | LineNumber: 0 | BytePositionInLine: 86.)
---> System.Text.Json.JsonException: The JSON value could not be converted to System.DateTimeOffset. Path: $.people[0].birthDate | LineNumber: 0 | BytePositionInLine: 86.
---> System.InvalidOperationException: Cannot get the value of a token type 'Null' as a string.

From the api explorer you can see that a person with no registered birthdate takes the following form:

        {
            "id": "04a38328-4202-44ef-9f2b-ee85b1cd1a48",
            "name": "Test",
            "birthDate": null,
            "thumbnailPath": "/data/thumbs/6bbe2767-7851-461a-aa2d-afbd3460aa85/04/a3/04a38328-4202-44ef-9f2b-ee85b1cd1a48.jpeg",
            "isHidden": false,
            "isFavorite": false,
            "updatedAt": "2026-01-23T11:52:27.606Z"
        }

And their OpenAPI spec does correctly declare birthDate as nullable:

     "PersonResponseDto": {
        "properties": {
          "birthDate": {
            "format": "date",
            "nullable": true,
            "type": "string"
          },

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions