Optimize encoding of Newtypes in Schema serialization
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 1.5k
- Forks
- 212
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 119
Description
The following feature request is written from a rust perspective but might also be valid for other languages.
Currently the following struct in rust, which is being used as a newtype, is being exposed as an object instead of the simplified encoding of simply the wrapped typed.
#[derive(Shrinkwrap, Schema, Debug, Clone, Copy)]
pub struct LobbyId(pub Uuid);
When this struct is being used as input or output of agents it results in the following json:
...
"id": {
"value": "dd00721b-3329-4621-a01d-c71f02cd78c6"
}
...
Instead the following encoding which should have all information to read and write the newtype is easier to read and also provide as input:
...
"id": "dd00721b-3329-4621-a01d-c71f02cd78c6"
...
It would be nice to have an option, so that wrapper structs simply wrapping one value (or annotated with a derive macro) would be serialized as described above.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the Rust Schema derive handling for single-field wrapper structs such as LobbyId(pub Uuid). Check how the current schema serialization produces the nested value object, then define the option or derive behavior described in the issue. Done means the wrapper can be read and written using the simplified scalar JSON encoding without losing schema information.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100