diff --git a/poem-openapi-derive/src/utils.rs b/poem-openapi-derive/src/utils.rs index 2fe6de43a9..f64e8d0c98 100644 --- a/poem-openapi-derive/src/utils.rs +++ b/poem-openapi-derive/src/utils.rs @@ -191,13 +191,13 @@ pub(crate) fn create_object_name( use ::std::convert::From; let mut name = ::std::string::String::from(#name); - name.push('<'); + name.push('_'); name.push_str(&<#first as #crate_name::types::Type>::name()); #( name.push_str(", "); name.push_str(&<#tail as #crate_name::types::Type>::name()); )* - name.push('>'); + name.push('_'); name }) diff --git a/poem-openapi/src/types/maybe_undefined.rs b/poem-openapi/src/types/maybe_undefined.rs index 48eda7755e..5604d1ce1c 100644 --- a/poem-openapi/src/types/maybe_undefined.rs +++ b/poem-openapi/src/types/maybe_undefined.rs @@ -151,6 +151,12 @@ impl MaybeUndefined { matches!(self, MaybeUndefined::Value(_)) } + /// Returns true if the `MaybeUndefined` contains value or is null. + #[inline] + pub const fn is_value_or_null(&self) -> bool { + matches!(self, MaybeUndefined::Value(_)) || matches!(self, MaybeUndefined::Null) + } + /// Returns `None` if the the `MaybeUndefined` is /// `undefined` or `null`, otherwise returns `Some(&T)`. #[inline] diff --git a/poem-openapi/tests/object.rs b/poem-openapi/tests/object.rs index 975f7badb7..bc2e389589 100644 --- a/poem-openapi/tests/object.rs +++ b/poem-openapi/tests/object.rs @@ -1,3 +1,4 @@ + use poem_openapi::{ registry::{MetaExternalDocument, MetaSchema, MetaSchemaRef, Registry}, types::{Example, ParseFromJSON, ToJSON, Type}, @@ -45,7 +46,7 @@ fn generics() { assert_eq!( >::name(), - "Obj" + "Obj_integer(int32), integer(int64)_" ); let meta = get_meta::>(); assert_eq!(meta.properties[0].1.unwrap_inline().ty, "integer"); @@ -56,7 +57,7 @@ fn generics() { assert_eq!( >::name(), - "Obj" + "Obj_number(float), number(double)_" ); let meta = get_meta::>(); assert_eq!(meta.properties[0].1.unwrap_inline().ty, "number"); diff --git a/poem-openapi/tests/union.rs b/poem-openapi/tests/union.rs index a784d3756f..3786a46041 100644 --- a/poem-openapi/tests/union.rs +++ b/poem-openapi/tests/union.rs @@ -514,11 +514,11 @@ async fn generics() { assert_eq!( >::schema_ref(), - MetaSchemaRef::Reference("MyObj".to_string()) + MetaSchemaRef::Reference("MyObj_integer(int32), integer(int64)_".to_string()) ); assert_eq!( >::schema_ref(), - MetaSchemaRef::Reference("MyObj".to_string()) + MetaSchemaRef::Reference("MyObj_number(float), number(double)_".to_string()) ); assert_eq!(schema_i32_i64.any_of[0], i32::schema_ref());