You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-07-29 22:01:14 +03:00
Add variants for unknown values on mas-iana types
Remove the Copy derive and mark enums as non-exhaustive.
This commit is contained in:
committed by
Quentin Gliech
parent
9e3b3567b2
commit
80d317f23c
@ -105,7 +105,7 @@ impl Display for File {
|
||||
|
||||
use parse_display::{{Display, FromStr}};
|
||||
use schemars::JsonSchema;
|
||||
use serde::{{Deserialize, Serialize}};"#,
|
||||
use serde_with::{{DeserializeFromStr, SerializeDisplay}};"#,
|
||||
self.registry_name, self.registry_url,
|
||||
)?;
|
||||
|
||||
@ -116,6 +116,14 @@ use serde::{{Deserialize, Serialize}};"#,
|
||||
continue;
|
||||
};
|
||||
|
||||
let is_exhaustive = section.key == "OAuthAuthorizationEndpointResponseType";
|
||||
|
||||
let non_exhaustive_attr = if is_exhaustive {
|
||||
""
|
||||
} else {
|
||||
"\n#[non_exhaustive]"
|
||||
};
|
||||
|
||||
write!(
|
||||
f,
|
||||
r#"
|
||||
@ -125,7 +133,6 @@ use serde::{{Deserialize, Serialize}};"#,
|
||||
#[derive(
|
||||
Debug,
|
||||
Clone,
|
||||
Copy,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
@ -133,13 +140,14 @@ use serde::{{Deserialize, Serialize}};"#,
|
||||
Hash,
|
||||
Display,
|
||||
FromStr,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
SerializeDisplay,
|
||||
DeserializeFromStr,
|
||||
JsonSchema,
|
||||
)]
|
||||
)]{}
|
||||
pub enum {} {{"#,
|
||||
section.doc,
|
||||
section.url.unwrap(),
|
||||
non_exhaustive_attr,
|
||||
section.key,
|
||||
)?;
|
||||
for member in list {
|
||||
@ -149,10 +157,20 @@ pub enum {} {{"#,
|
||||
} else {
|
||||
writeln!(f, " /// `{}`", member.value)?;
|
||||
}
|
||||
writeln!(f, " #[serde(rename = \"{}\")]", member.value)?;
|
||||
writeln!(f, " #[schemars(rename = \"{}\")]", member.value)?;
|
||||
writeln!(f, " #[display(\"{}\")]", member.value)?;
|
||||
writeln!(f, " {},", member.enum_name)?;
|
||||
}
|
||||
|
||||
if !is_exhaustive {
|
||||
// Add a variant for custom enums
|
||||
writeln!(f)?;
|
||||
writeln!(f, " /// An unknown value.")?;
|
||||
writeln!(f, " #[display(\"{{0}}\")]")?;
|
||||
writeln!(f, " #[schemars(skip)]")?;
|
||||
writeln!(f, " Unknown(String),")?;
|
||||
}
|
||||
|
||||
writeln!(f, "}}")?;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user