Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

close #670; fix: replace <> with _ in generic object names #671

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions poem-openapi-derive/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
6 changes: 6 additions & 0 deletions poem-openapi/src/types/maybe_undefined.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,12 @@ impl<T> MaybeUndefined<T> {
matches!(self, MaybeUndefined::Value(_))
}

/// Returns true if the `MaybeUndefined<T>` 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<T>` is
/// `undefined` or `null`, otherwise returns `Some(&T)`.
#[inline]
Expand Down
5 changes: 3 additions & 2 deletions poem-openapi/tests/object.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

use poem_openapi::{
registry::{MetaExternalDocument, MetaSchema, MetaSchemaRef, Registry},
types::{Example, ParseFromJSON, ToJSON, Type},
Expand Down Expand Up @@ -46,7 +47,7 @@ fn generics() {

assert_eq!(
<Obj<i32, i64>>::name(),
"Obj<integer(int32), integer(int64)>"
"Obj_integer(int32), integer(int64)_"
);
let meta = get_meta::<Obj<i32, i64>>();
assert_eq!(meta.properties[0].1.unwrap_inline().ty, "integer");
Expand All @@ -57,7 +58,7 @@ fn generics() {

assert_eq!(
<Obj<f32, f64>>::name(),
"Obj<number(float), number(double)>"
"Obj_number(float), number(double)_"
);
let meta = get_meta::<Obj<f32, f64>>();
assert_eq!(meta.properties[0].1.unwrap_inline().ty, "number");
Expand Down
4 changes: 2 additions & 2 deletions poem-openapi/tests/union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -506,11 +506,11 @@ async fn generics() {

assert_eq!(
<MyObj<i32, i64>>::schema_ref(),
MetaSchemaRef::Reference("MyObj<integer(int32), integer(int64)>".to_string())
MetaSchemaRef::Reference("MyObj_integer(int32), integer(int64)_".to_string())
);
assert_eq!(
<MyObj<f32, f64>>::schema_ref(),
MetaSchemaRef::Reference("MyObj<number(float), number(double)>".to_string())
MetaSchemaRef::Reference("MyObj_number(float), number(double)_".to_string())
);

assert_eq!(schema_i32_i64.any_of[0], i32::schema_ref());
Expand Down