Resolve type aliases based on inferred types.

Before this commit, we would always show the 'declared form' of type aliases, with their generic, non-instantiated parameters. This now tries to unify the annotation with the underlying inferred type to provide even better alias pretty printing.
This commit is contained in:
KtorZ
2024-03-08 15:53:41 +01:00
parent ed9f5c6ef7
commit a578728a94
9 changed files with 383 additions and 134 deletions

View File

@@ -1125,13 +1125,11 @@ pub mod tests {
#[test]
fn serialize_data_constr_1() {
let schema = Schema::Data(Data::AnyOf(vec![
Constructor {
index: 0,
fields: vec![],
}
.into(),
]));
let schema = Schema::Data(Data::AnyOf(vec![Constructor {
index: 0,
fields: vec![],
}
.into()]));
assert_json(
&schema,
json!({
@@ -1292,16 +1290,14 @@ pub mod tests {
#[test]
fn deserialize_any_of() {
assert_eq!(
Data::AnyOf(vec![
Constructor {
index: 0,
fields: vec![
Declaration::Referenced(Reference::new("foo")).into(),
Declaration::Referenced(Reference::new("bar")).into()
],
}
.into()
]),
Data::AnyOf(vec![Constructor {
index: 0,
fields: vec![
Declaration::Referenced(Reference::new("foo")).into(),
Declaration::Referenced(Reference::new("bar")).into()
],
}
.into()]),
serde_json::from_value(json!({
"anyOf": [{
"index": 0,
@@ -1322,16 +1318,14 @@ pub mod tests {
#[test]
fn deserialize_one_of() {
assert_eq!(
Data::AnyOf(vec![
Constructor {
index: 0,
fields: vec![
Declaration::Referenced(Reference::new("foo")).into(),
Declaration::Referenced(Reference::new("bar")).into()
],
}
.into()
]),
Data::AnyOf(vec![Constructor {
index: 0,
fields: vec![
Declaration::Referenced(Reference::new("foo")).into(),
Declaration::Referenced(Reference::new("bar")).into()
],
}
.into()]),
serde_json::from_value(json!({
"oneOf": [{
"index": 0,

View File

@@ -11,6 +11,7 @@ Schema {
module: "test_module",
name: "Rational",
args: [],
alias: None,
},
],
},

View File

@@ -19,9 +19,11 @@ Schema {
module: "test_module",
name: "UUID",
args: [],
alias: None,
},
},
},
alias: None,
},
Var {
tipo: RefCell {
@@ -31,11 +33,14 @@ Schema {
module: "",
name: "Int",
args: [],
alias: None,
},
},
},
alias: None,
},
],
alias: None,
},
],
},