Test for default name of struct with type params
This commit is contained in:
parent
54cfd2ba0e
commit
d14db450cf
4 changed files with 100 additions and 2 deletions
|
@ -306,6 +306,18 @@ impl<T: MakeSchema> MakeSchema for Option<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<T> MakeSchema for std::marker::PhantomData<T> {
|
||||
no_ref_schema!();
|
||||
|
||||
fn schema_name() -> String {
|
||||
<()>::schema_name()
|
||||
}
|
||||
|
||||
fn make_schema(gen: &mut SchemaGenerator) -> Result {
|
||||
<()>::make_schema(gen)
|
||||
}
|
||||
}
|
||||
|
||||
////////// DEREF //////////
|
||||
|
||||
macro_rules! deref_impl {
|
||||
|
|
87
schemars/tests/naming.rs
Normal file
87
schemars/tests/naming.rs
Normal file
|
@ -0,0 +1,87 @@
|
|||
use pretty_assertions::assert_eq;
|
||||
use schemars::{schema_for, MakeSchema};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::error::Error;
|
||||
|
||||
const EXPECTED: &str = r#"
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-07/schema#",
|
||||
"title": "MyStruct_For_Integer_And_Null_And_Boolean_And_Array_Of_String",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"float": {
|
||||
"type": "number"
|
||||
},
|
||||
"t": {
|
||||
"type": "integer"
|
||||
},
|
||||
"u": {
|
||||
"type": "null"
|
||||
},
|
||||
"v": {
|
||||
"type": "boolean"
|
||||
},
|
||||
"w": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
"#;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, MakeSchema)]
|
||||
struct MyStruct<T, U, V, W> {
|
||||
t: T,
|
||||
u: U,
|
||||
float: f32,
|
||||
v: V,
|
||||
w: W,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, MakeSchema)]
|
||||
#[serde(rename = "MyStruct")]
|
||||
struct MyRenamedStruct<T, U, V, W> {
|
||||
t: T,
|
||||
u: U,
|
||||
float: f32,
|
||||
v: V,
|
||||
w: W,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, MakeSchema)]
|
||||
#[serde(remote = "MyStruct")]
|
||||
struct MyRemoteStruct<T, U, V, W> {
|
||||
t: T,
|
||||
u: U,
|
||||
float: f32,
|
||||
v: V,
|
||||
w: W,
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn default_name_multiple_type_params() -> Result<(), Box<dyn Error>> {
|
||||
let actual = schema_for!(MyStruct<i32, (), bool, Vec<String>>)?;
|
||||
let expected = serde_json::from_str(EXPECTED)?;
|
||||
assert_eq!(actual, expected);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore] // not yet implemented
|
||||
fn overriden_with_rename_name_multiple_type_params() -> Result<(), Box<dyn Error>> {
|
||||
let actual = schema_for!(MyRenamedStruct<i32, (), bool, Vec<String>>)?;
|
||||
let expected = serde_json::from_str(EXPECTED)?;
|
||||
assert_eq!(actual, expected);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore] // not yet implemented
|
||||
fn overriden_with_remote_name_multiple_type_params() -> Result<(), Box<dyn Error>> {
|
||||
let actual = schema_for!(MyRemoteStruct<i32, (), bool, Vec<String>>)?;
|
||||
let expected = serde_json::from_str(EXPECTED)?;
|
||||
assert_eq!(actual, expected);
|
||||
Ok(())
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue