Skip to content

Commit

Permalink
Feat std::collections::LinkedList as a known field type for schema (#748
Browse files Browse the repository at this point in the history
)

Add support for `std::collection::LinkedList`. This commit makes `LinkedList` 
work as `Vec` in schema generation.
  • Loading branch information
evgenymng authored Aug 31, 2023
1 parent 2eecc9a commit 1443ec4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
10 changes: 10 additions & 0 deletions utoipa-gen/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ impl<'t> TypeTree<'t> {
#[cfg(feature = "indexmap")]
"IndexMap" => Some(GenericType::Map),
"Vec" => Some(GenericType::Vec),
"LinkedList" => Some(GenericType::LinkedList),
#[cfg(feature = "smallvec")]
"SmallVec" => Some(GenericType::SmallVec),
"Option" => Some(GenericType::Option),
Expand Down Expand Up @@ -391,6 +392,7 @@ pub enum ValueType {
#[derive(PartialEq, Eq, Clone, Copy)]
pub enum GenericType {
Vec,
LinkedList,
#[cfg(feature = "smallvec")]
SmallVec,
Map,
Expand Down Expand Up @@ -493,6 +495,14 @@ impl<'c> ComponentSchema {
description_stream,
deprecated_stream,
),
Some(GenericType::LinkedList) => ComponentSchema::vec_to_tokens(
&mut tokens,
features,
type_tree,
object_name,
description_stream,
deprecated_stream,
),
#[cfg(feature = "smallvec")]
Some(GenericType::SmallVec) => ComponentSchema::vec_to_tokens(
&mut tokens,
Expand Down
28 changes: 28 additions & 0 deletions utoipa-gen/tests/schema_derive_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3583,6 +3583,34 @@ fn derive_component_with_raw_identifier() {
)
}

#[test]
fn derive_component_with_linked_list() {
use std::collections::LinkedList;

let example_schema = api_doc! {
struct ExampleSchema {
values: LinkedList<f64>
}
};

assert_json_eq!(
example_schema,
json!({
"properties": {
"values": {
"items": {
"type": "number",
"format": "double"
},
"type": "array"
}
},
"required": ["values"],
"type": "object"
})
)
}

#[test]
#[cfg(feature = "smallvec")]
fn derive_component_with_smallvec_feature() {
Expand Down

0 comments on commit 1443ec4

Please sign in to comment.