Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse more values to appropriate types #377

Open
philippeitis opened this issue Oct 5, 2022 · 1 comment
Open

Parse more values to appropriate types #377

philippeitis opened this issue Oct 5, 2022 · 1 comment

Comments

@philippeitis
Copy link
Collaborator

philippeitis commented Oct 5, 2022

Certain values don't currently use the appropriate types as described by the schema - it seems that due to JSON limitations, Google might use strings to encode numbers - a few examples below, taken from the drive-api.json file:

"version": {
    "description": "A monotonically increasing version number for the file. This reflects every change made to the file on the server, even those not visible to the user.",
    "format": "int64",
    "type": "string"
}
"durationMillis": {
    "description": "The duration of the video in milliseconds.",
    "format": "int64",
    "type": "string"
}
"size": {
    "description": "The size of the revision's content in bytes. This is only applicable to files with binary content in Drive.",
    "format": "int64",
    "type": "string"
}

This results in me having to write code like this:

let size = u64::from_str(&file.size.unwrap()).unwrap();

Even though the file size is known to be an integer, and it should really be parsed by the API.

This seems to be due to this map:

TYPE_MAP = {'boolean' : 'bool',

And this block of code:

I think the fix would be to default to using the format specifier first, falling back to the type specifier if the format is not present / supported.

However, this would require a breaking change, so I want to ask about how this should be handled before making any changes.

It would also be nice to support "date-time" format values, but that would require pulling in additional dependencies, which may not be desirable. I think it would be nice to provide base64 decoding / encoding for "byte" format values, to ensure that those values are constructed correctly.

All of the unsupported formats I found:

  • google-duration
  • byte
  • google-datetime
  • date-time
  • google-fieldmask
  • date
@Byron
Copy link
Owner

Byron commented Oct 7, 2022

Thanks a lot for bringing this up! I remember having left the type-system to be just barely good enough to be acceptable for the use-case I had back then, and agree that improvements are desirable and possible.

However, this would require a breaking change, so I want to ask about how this should be handled before making any changes.

I am absolutely open to that, it seems to be a worthy cause. Even though the version number was incremented to 4.0 not too long ago, the crates have not actually been republished. By going to 5.0 it would mean people have to deal with a couple of additional breaking changes, which I think is probably worth it for them if they consider the upgrade in the first place.

It would also be nice to support "date-time" format values, but that would require pulling in additional dependencies, which may not be desirable. I think it would be nice to provide base64 decoding / encoding for "byte" format values, to ensure that those values are constructed correctly.

I definitely wouldn't mind, and rather throw CPU time at a problem than human time. If there is high demand, a feature toggle could be added later to avoid those newly added dependencies.

A PR with such an improvement is definitely welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants