juhaku/utoipa

Allow alias for serde_json::Value: Gobal Rusts Type Alias registry

JoverZhang opened this issue · 1 comments

Hello.

Instead of using serde_json::Value directly, we added an alias Json for serde_json::Value.

But the Json won't be recognized as serde_json::Value.

pub type Json = serde_json::Value;

This would make it recognizable, but that doesn't make much sense.

pub struct VO {
  #[schema(value_type = HashMap<String, serde_json::Value>)]
  pub fields: HashMap<String, Json>,
}

Could it be like #[aliases], where to write it once, and it's consistently recognized as serde_json::Value?

Could it be like #[aliases], where to write it once, and it's consistently recognized as serde_json::Value?

Unfortunately this is not possible at the moment. This needs a global registry for the type aliases that is available for the macro compile process. This would need some experimenting in order to find the right solution. This is not straight forward to implement to my reckoning, yet the support would be quite beneficial for the library and the users. Definitely something that can be investigated in future.