-
-
Notifications
You must be signed in to change notification settings - Fork 135
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
Use schema format over type #379
Conversation
I've identified that the JSON representation for I've managed to use I can't find a source which states that The last type is I also need to update the generated READMEs to use the correct constructors. |
1687fa0
to
928c602
Compare
That should be all of the previously unsupported types, with appropriate unit tests and example types. While I still want to do some testing on actual API calls, this PR should be mostly ready to go. I've included some links / information about where I found type descriptions/definitions in |
If using #[serde(with = ...)] with an Option type, serde will expect all marked fields to be present. Adding #[serde(default)] restores expected behaviour - if no Option value is present, None will be used.
7aaf2d5
to
ddac761
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for your incredible effort, they are, as always, much appreciated!
I glanced at the changes and they looked alright, while running make cargo-api ARGS=check
in the background. It stopped at accesscontextmanager1
with:
Checking google-accesscontextmanager1 v4.0.4+20220301 (/Users/byron/dev/github.com/Byron/google-apis-rs/gen/accesscontextmanager1)
error[E0277]: the trait bound `FieldMask: Clone` is not satisfied
--> src/api.rs:957:5
|
950 | #[derive(Default, Clone, Debug, Serialize, Deserialize)]
| ----- in this derive macro expansion
...
957 | pub update_mask: Option<client::FieldMask>,
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Clone` is not implemented for `FieldMask`
|
= note: required because of the requirements on the impl of `Clone` for `std::option::Option<FieldMask>`
Can you reproduce this and maybe get it to run through on all APIs as well? Then I'd think a merge shouldn't be far.
I've included some links / information about where I found type descriptions/definitions in util.py, but I'm happy to put these links somewhere else.
To me this location seems like a great starting point and it felt intuitive to read them there. I'd keep them there until there is demand for a change or a vastly better place is presenting itself.
Thanks a lot!
The serde traits are now directly implemented for FieldMask - this helps address potential serde issues with wrapper types, and simplifies the serde process somewhat.
3a50d2d
to
8cc2707
Compare
This introduces the `serde_with` dependency and `rust_type.py`, to allow supporting arbitrary types for serialization. Since fields may have arbitrary types (eg. `HashMap<_, chrono::Duration>`) which need deserialization, it is necessary to use type-based serialization to avoid implementing (de)serialization for every permutation of types that require special serialization. However, `serde` does not let you (de)serialize one type as another (eg. `chrono::Duration` as `Wrapper`) - thus necessitating `serde_with`, which does. `rust_type.py` introduces the `RustType` class, which makes it easy to describe the (de)serialization type used by `serde_with`
I've managed to get
|
This is amazing work! I'd even call it 'magical' as I always have trouble wrapping my head about Introducing If you would ever be open to a maintainer role in this project, I'd be happy to send you an invite. |
|
This is a draft PR which includes the basic fix, allowing more values to be deserialized correctly.
To handle Google specific types, I've included a rudimentary implementation for base64 and
Duration
encode/decode.The
Duration
struct can simply be imported where necessary, and implements serde directly.However, the base64 encoding / decoding requires custom attributes to utilize the appropriate serde functions (as we'd want it to be
Vec<u8>
).This leaves 3 date-time types, and one fieldmask type. Unfortunately, it is somewhat difficult to track down the concrete type definitions, so I'm not entirely confident that the implementations thus far are correct.
However, I think this go package might be relevant: https://pkg.go.dev/google.golang.org/protobuf/types
(Incidentally, it would be nice to support protobuf APIs for supported endpoints - something I'd like to look at in the future)
PR for #377