Fix reference JSON deserialization.
This commit is contained in:
parent
c18deecdc8
commit
bf222a3ea2
|
@ -224,9 +224,16 @@ impl<'a> Deserialize<'a> for Reference {
|
|||
}
|
||||
}
|
||||
|
||||
Ok(Reference {
|
||||
inner: inner.ok_or_else(|| de::Error::missing_field(FIELDS[0]))?,
|
||||
})
|
||||
let inner: String = inner.ok_or_else(|| de::Error::missing_field(FIELDS[0]))?;
|
||||
|
||||
match inner.strip_prefix("#/definitions/") {
|
||||
Some(suffix) => Ok(Reference {
|
||||
inner: suffix.to_string(),
|
||||
}),
|
||||
None => Err(de::Error::custom(
|
||||
"Invalid reference; only local JSON pointer to #/definitions are allowed.",
|
||||
)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1244,7 +1244,7 @@ pub mod test {
|
|||
Data::List(Items::One(Declaration::Referenced(Reference::new("foo")))),
|
||||
serde_json::from_value(json!({
|
||||
"dataType": "list",
|
||||
"items": { "$ref": "foo" }
|
||||
"items": { "$ref": "#/definitions/foo" }
|
||||
}))
|
||||
.unwrap()
|
||||
)
|
||||
|
@ -1260,8 +1260,8 @@ pub mod test {
|
|||
serde_json::from_value(json!({
|
||||
"dataType": "list",
|
||||
"items": [
|
||||
{ "$ref": "foo" },
|
||||
{ "$ref": "bar" }
|
||||
{ "$ref": "#/definitions/foo" },
|
||||
{ "$ref": "#/definitions/bar" }
|
||||
],
|
||||
}))
|
||||
.unwrap()
|
||||
|
@ -1277,8 +1277,8 @@ pub mod test {
|
|||
),
|
||||
serde_json::from_value(json!({
|
||||
"dataType": "map",
|
||||
"keys": { "$ref": "foo" },
|
||||
"values": { "$ref": "bar" }
|
||||
"keys": { "$ref": "#/definitions/foo" },
|
||||
"values": { "$ref": "#/definitions/bar" }
|
||||
}))
|
||||
.unwrap()
|
||||
)
|
||||
|
@ -1300,10 +1300,10 @@ pub mod test {
|
|||
"index": 0,
|
||||
"fields": [
|
||||
{
|
||||
"$ref": "foo",
|
||||
"$ref": "#/definitions/foo",
|
||||
},
|
||||
{
|
||||
"$ref": "bar",
|
||||
"$ref": "#/definitions/bar",
|
||||
}
|
||||
]
|
||||
}]
|
||||
|
@ -1328,10 +1328,10 @@ pub mod test {
|
|||
"index": 0,
|
||||
"fields": [
|
||||
{
|
||||
"$ref": "foo",
|
||||
"$ref": "#/definitions/foo",
|
||||
},
|
||||
{
|
||||
"$ref": "bar",
|
||||
"$ref": "#/definitions/bar",
|
||||
}
|
||||
]
|
||||
}]
|
||||
|
|
Loading…
Reference in New Issue