-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor alises support on
ToSchema
derive (#546)
Prior to this commit the implementation was not able to resolve nested generics within aliases. That lead scenarios where types with extensive use of lifetimes was not possible. This commit takes another approach on aliases support for `ToSchema` derive macro that provides generic schema types. Instead of trying to parse `Generics` manually we parse `syn::Type` instead that contains generics as is allowing complex generic arguments with lifetimes to be used. Fundamental difference is that we create `TypeTree` for alias and the implementor type. Then we compare generic arguments to the field arguments and replace matching occurrences. ```rust #[derive(ToSchema)] #[aliases(Paginated1 = Paginated<'b, String>, Paginated2 = Paginated<'b, Cow<'b, bool>>)] struct Paginated<'r, T> { pub total: usize, pub data: Vec<T>, pub next: Option<&'r str>, pub prev: Option<&'r str>, } ``` Also removed the need to define lifetime on left side of the equals (=) sign.
- Loading branch information
Showing
5 changed files
with
78 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters