-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix impl
ToSchema
for container types (#1107)
This PR fixes implementation of `ToSchema` on container types like `Vec<T>` or `Option<T>`. Prior to this commit it was not implemented which resulted errors when such types was used as generic argument. This commit fixes this which correctly allows following syntax. ```rust #[derive(ToSchema)] pub struct FooStruct<B> { pub foo: B, } #[derive(ToSchema)] enum FoosEnum { ThingNoAliasOption(FooStruct<Option<i32>>), FooEnumThing(#[schema(inline)] FooStruct<Vec<i32>>), FooThingOptionVec(#[schema(inline)] FooStruct<Option<Vec<i32>>>), FooThingLinkedList(#[schema(inline)] FooStruct<std::collections::LinkedList<i32>>), FooThingBTreeMap(#[schema(inline)] FooStruct<std::collections::BTreeMap<String, String>>), FooThingHashMap(#[schema(inline)] FooStruct<std::collections::HashMap<i32, String>>), FooThingHashSet(#[schema(inline)] FooStruct<std::collections::HashSet<i32>>), FooThingBTreeSet(#[schema(inline)] FooStruct<std::collections::BTreeSet<i32>>), } ``` **Note!** Currently generic argument cannot be `slice`, `array` or `tuple`. That is a hard limitation of current `TypeTree` implementation and would need some work before such types were supported. Relates #1034 Fixes #1099
- Loading branch information
Showing
8 changed files
with
850 additions
and
162 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
"openapi": "3.1.0", | ||
"info": { | ||
"title": "title", | ||
"version": "version" | ||
}, | ||
"paths": {}, | ||
"components": { | ||
"schemas": { | ||
"HighArc": { | ||
"$ref": "#/components/schemas/High_Arc_i32" | ||
}, | ||
"HighRc": { | ||
"$ref": "#/components/schemas/High_Rc_i32" | ||
}, | ||
"High_Arc_i32": { | ||
"type": "object", | ||
"required": [ | ||
"high" | ||
], | ||
"properties": { | ||
"high": { | ||
"type": "integer", | ||
"format": "int32" | ||
} | ||
} | ||
}, | ||
"High_Rc_i32": { | ||
"type": "object", | ||
"required": [ | ||
"high" | ||
], | ||
"properties": { | ||
"high": { | ||
"type": "integer", | ||
"format": "int32" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.