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

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

Closed
JoverZhang opened this issue Sep 19, 2023 · 3 comments · Fixed by #1048
Closed

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

JoverZhang opened this issue Sep 19, 2023 · 3 comments · Fixed by #1048
Labels
Aliases Work for global aliases

Comments

@JoverZhang
Copy link

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?

@juhaku
Copy link
Owner

juhaku commented Nov 8, 2023

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.

@juhaku juhaku changed the title Allow alias for serde_json::Value Allow alias for serde_json::Value: Gobal Rusts Type Alias registry Nov 8, 2023
@juhaku
Copy link
Owner

juhaku commented Sep 9, 2024

Related #766, #790 #787

@juhaku juhaku added the Aliases Work for global aliases label Sep 9, 2024
juhaku added a commit that referenced this issue Sep 12, 2024
This PR adds global config for `utiopa` which allows defining global
Rust type aliases that can be recognized by `utoipa`.

```rust
 let _ = Config::new()
     .alias_for("MyType", "i32");
     .alias_for("Json", "Value");
     .alias_for("NullableString", "Option<String>");
```

Closes #984 Closes #787 Closes #766 Closes #429
@juhaku juhaku moved this to In Progress in utoipa kanban Sep 12, 2024
@juhaku
Copy link
Owner

juhaku commented Sep 12, 2024

@JoverZhang There is now coming a new PR which adds global type aliases for utoipa #1048.

@juhaku juhaku closed this as completed in e66b4ed Sep 12, 2024
@github-project-automation github-project-automation bot moved this from In Progress to Done in utoipa kanban Sep 12, 2024
@juhaku juhaku moved this from Done to Released in utoipa kanban Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Aliases Work for global aliases
Projects
Status: Released
Development

Successfully merging a pull request may close this issue.

2 participants