Traccar OpenAPI Client get_users: expirationTime can be null but is not marked as nullable

Smashers09015 hours ago

Background

I installed the Traccar API client to a python environment using openapi-python-client.

openapi-python-client generate --url https://raw.githubusercontent.com/traccar/traccar/master/openapi.yaml --output-path traccar_client

Issue

A GET request to /api/users using the generated client (traccar_client.api.users.get_users) resulted in an issue.

File ".../traccar_client/models/user.py", line 198, in from_dict
    expiration_time = isoparse(_expiration_time)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
...
TypeError: object of type 'NoneType' has no len()

This happens because the expiration_time field in the User model is None, and isoparse from the dateutil library cannot handle None values.

The root cause is that the expirationTime field in the Traccar API response can be null, but the generated client code doesn't handle this case properly. This is because the expirationTime property in the OpenAPI specification isn't marked as nullable.

expirationTime:
  type: string
  format: date-time

Solution

Modify the OpenAPI specification to include nullable: true

expirationTime:
  type: string
  format: date-time
  nullable: true

Next steps

I will modify a copy of the OpenAPI spec to get past the issue on my side, but wanted to flag it so the master version can be updated, if considered appropriate by devs.

Thanks

Anton Tananaev15 hours ago

Feel free to send a pull request to update the OpenAPI spec.

Smashers09015 hours ago

That's done. Thanks