Detect header attributes as name/value pairs.

This commit is contained in:
Jimmy Cuadra 2018-05-15 22:57:06 -07:00
parent a035c233be
commit f0f4f9bd17
2 changed files with 26 additions and 24 deletions

View File

@ -96,21 +96,22 @@ impl From<Vec<Field>> for Request {
has_newtype_body = true;
field_kind = RequestFieldKind::NewtypeBody;
}
"header" => field_kind = RequestFieldKind::Header,
"path" => field_kind = RequestFieldKind::Path,
"query" => field_kind = RequestFieldKind::Query,
_ => panic!(
"ruma_api! attribute meta item on requests must be: body, header, path, or query"
),
_ => panic!("ruma_api! single-word attribute on requests must be: body, path, or query"),
}
}
_ => panic!(
"ruma_api! attribute meta item on requests cannot be a list or name/value pair"
),
Meta::NameValue(name_value) => {
match name_value.ident.as_ref() {
"header" => field_kind = RequestFieldKind::Header,
_ => panic!("ruma_api! name/value pair attribute on requests must be: header"),
}
}
_ => panic!("ruma_api! attributes on requests must be a single word or a name/value pair"),
}
}
NestedMeta::Literal(_) => panic!(
"ruma_api! attribute meta item on requests must be: body, header, path, or query"
"ruma_api! attributes on requests must be: body, header, path, or query"
),
}
}

View File

@ -104,15 +104,16 @@ impl From<Vec<Field>> for Response {
has_newtype_body = true;
field_kind = ResponseFieldKind::NewtypeBody;
}
_ => panic!("ruma_api! single-word attribute on responses must be: body"),
}
}
Meta::NameValue(name_value) => {
match name_value.ident.as_ref() {
"header" => field_kind = ResponseFieldKind::Header,
_ => panic!(
"ruma_api! attribute meta item on responses must be: header"
),
_ => panic!("ruma_api! name/value pair attribute on requests must be: header"),
}
}
_ => panic!(
"ruma_api! attribute meta item on responses cannot be a list or name/value pair"
),
_ => panic!("ruma_api! attributes on responses must be a single word or a name/value pair"),
}
}
NestedMeta::Literal(_) => panic!(