serde icon indicating copy to clipboard operation
serde copied to clipboard

How can I dump all possible path of a deserializable struct?

Open tisonkun opened this issue 1 year ago • 2 comments

Suppose I have a Config structure that have several nested options, some of them use #[serde(tag = "type")] or more serde attrs.

I'd like to get a table of all possible paths of Config, said:

  • server.http.listern_addr is a String
  • storage.type can be s3, azblob, etc.
  • storage.bucket is a String.

Is there some way to dump such a schema?

Alternatively, I can enumerate the paths by myself, but in this case, I'd like to write a test to ensure that all the paths are valid (can exist).

tisonkun avatar Jan 16 '25 17:01 tisonkun

https://github.com/zefchain/serde-reflection/tree/main/serde-reflection does this.

dtolnay avatar Jan 16 '25 17:01 dtolnay

Good to know. Although, serde-reflection seems doesn't support #[serde(tag = "type")]:

Attributes that are not compatible with binary formats (e.g. #[serde(flatten)], #[serde(tag = ..)])

I noticed serde-reflection refers to schemars, where I'm waiting for https://github.com/GREsau/schemars/pull/364.

Anyway, this may not something can be done at serde itself. Just I'd like to know if anything else I'm missing.

tisonkun avatar Jan 17 '25 12:01 tisonkun