diff --git a/crates/oapi-macros/src/component.rs b/crates/oapi-macros/src/component.rs index 7126d5308..761dfffd9 100644 --- a/crates/oapi-macros/src/component.rs +++ b/crates/oapi-macros/src/component.rs @@ -67,6 +67,15 @@ impl<'c> ComponentSchema { deprecated_stream, type_definition, ), + Some(GenericType::Set) => ComponentSchema::vec_to_tokens( + &mut tokens, + features, + type_tree, + object_name, + description_stream, + deprecated_stream, + type_definition, + ), #[cfg(feature = "smallvec")] Some(GenericType::SmallVec) => ComponentSchema::vec_to_tokens( &mut tokens, @@ -212,6 +221,8 @@ impl<'c> ComponentSchema { .next() .expect("CompnentSchema Vec should have 1 child"); + let unique = matches!(type_tree.generic_type, Some(GenericType::Set)); + // is octet-stream let schema = if child .path @@ -234,8 +245,16 @@ impl<'c> ComponentSchema { type_definition, }); + let unique = match unique { + true => quote! { + .unique_items(true) + }, + false => quote! {}, + }; + quote! { #oapi::oapi::schema::Array::new(#component_schema) + #unique } }; diff --git a/crates/oapi-macros/src/operation/mod.rs b/crates/oapi-macros/src/operation/mod.rs index e4bf75eaa..325d0cda3 100644 --- a/crates/oapi-macros/src/operation/mod.rs +++ b/crates/oapi-macros/src/operation/mod.rs @@ -279,7 +279,7 @@ impl PathTypeTree for TypeTree<'_> { /// Check whether [`TypeTree`] is a Vec, slice, array or other supported array type fn is_array(&self) -> bool { match self.generic_type { - Some(GenericType::Vec) => true, + Some(GenericType::Vec | GenericType::Set) => true, Some(_) => self.children.as_ref().unwrap().iter().any(|child| child.is_array()), None => false, } diff --git a/crates/oapi-macros/src/type_tree.rs b/crates/oapi-macros/src/type_tree.rs index b9ad3739f..fd00c2348 100644 --- a/crates/oapi-macros/src/type_tree.rs +++ b/crates/oapi-macros/src/type_tree.rs @@ -199,6 +199,7 @@ impl<'t> TypeTree<'t> { #[cfg(feature = "indexmap")] "IndexMap" => Some(GenericType::Map), "Vec" => Some(GenericType::Vec), + "BTreeSet" | "HashSet" => Some(GenericType::Set), "LinkedList" => Some(GenericType::LinkedList), #[cfg(feature = "smallvec")] "SmallVec" => Some(GenericType::SmallVec), @@ -273,6 +274,7 @@ pub(crate) enum ValueType { pub(crate) enum GenericType { Vec, LinkedList, + Set, #[cfg(feature = "smallvec")] SmallVec, Map, diff --git a/crates/oapi/src/openapi/schema/mod.rs b/crates/oapi/src/openapi/schema/mod.rs index eb327d294..cd9039ee4 100644 --- a/crates/oapi/src/openapi/schema/mod.rs +++ b/crates/oapi/src/openapi/schema/mod.rs @@ -786,10 +786,9 @@ mod tests { discriminator.mapping = [("int".to_string(), "#/components/schemas/MyInt".to_string())] .into_iter() .collect::>(); - let one_of = OneOfBuilder::new() + let one_of = OneOf::new() .item(Ref::from_schema_name("MyInt")) - .discriminator(Some(discriminator)) - .build(); + .discriminator(discriminator); let json_value = serde_json::to_value(one_of).unwrap(); assert_json_eq!(