You've already forked authentication-service
mirror of
https://github.com/matrix-org/matrix-authentication-service.git
synced 2025-12-10 01:01:09 +03:00
iana: manually implement JsonSchema/Display/FromStr/Serialize/Deserialize
This removes the dependency on serde_with and parse-display, and makes the serde & schemars dependencies optional
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
// Copyright 2022, 2023 The Matrix.org Foundation C.I.C.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@@ -23,6 +23,7 @@ use reqwest::Client;
|
||||
use tokio::io::AsyncWriteExt;
|
||||
use tracing::Level;
|
||||
|
||||
mod gen;
|
||||
pub mod jose;
|
||||
pub mod oauth;
|
||||
pub mod traits;
|
||||
@@ -82,10 +83,11 @@ impl File {
|
||||
}
|
||||
|
||||
impl Display for File {
|
||||
#[allow(clippy::too_many_lines)]
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
writeln!(
|
||||
f,
|
||||
r#"// Copyright 2022 The Matrix.org Foundation C.I.C.
|
||||
r#"// Copyright 2023 The Matrix.org Foundation C.I.C.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
@@ -102,11 +104,7 @@ impl Display for File {
|
||||
//! Enums from the {:?} IANA registry
|
||||
//! See <{}>
|
||||
|
||||
// Do not edit this file manually
|
||||
|
||||
use parse_display::{{Display, FromStr}};
|
||||
use schemars::JsonSchema;
|
||||
use serde_with::{{DeserializeFromStr, SerializeDisplay}};"#,
|
||||
// Do not edit this file manually"#,
|
||||
self.registry_name, self.registry_url,
|
||||
)?;
|
||||
|
||||
@@ -116,61 +114,25 @@ use serde_with::{{DeserializeFromStr, SerializeDisplay}};"#,
|
||||
};
|
||||
|
||||
let is_exhaustive = section.key == "OAuthAuthorizationEndpointResponseType";
|
||||
writeln!(f)?;
|
||||
|
||||
let non_exhaustive_attr = if is_exhaustive {
|
||||
""
|
||||
} else {
|
||||
"\n#[non_exhaustive]"
|
||||
};
|
||||
self::gen::struct_def(f, section, list, is_exhaustive)?;
|
||||
writeln!(f)?;
|
||||
|
||||
write!(
|
||||
f,
|
||||
r#"
|
||||
/// {}
|
||||
///
|
||||
/// Source: <{}>
|
||||
#[derive(
|
||||
Debug,
|
||||
Clone,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
Hash,
|
||||
Display,
|
||||
FromStr,
|
||||
SerializeDisplay,
|
||||
DeserializeFromStr,
|
||||
JsonSchema,
|
||||
)]{}
|
||||
pub enum {} {{"#,
|
||||
section.doc,
|
||||
section.url.unwrap(),
|
||||
non_exhaustive_attr,
|
||||
section.key,
|
||||
)?;
|
||||
for member in list {
|
||||
writeln!(f)?;
|
||||
if let Some(description) = &member.description {
|
||||
writeln!(f, " /// {description}")?;
|
||||
} else {
|
||||
writeln!(f, " /// `{}`", member.value)?;
|
||||
}
|
||||
writeln!(f, " #[schemars(rename = \"{}\")]", member.value)?;
|
||||
writeln!(f, " #[display(\"{}\")]", member.value)?;
|
||||
writeln!(f, " {},", member.enum_name)?;
|
||||
}
|
||||
// Write the Display impl
|
||||
self::gen::display_impl(f, section, list, is_exhaustive)?;
|
||||
writeln!(f)?;
|
||||
|
||||
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),")?;
|
||||
}
|
||||
// Write the FromStr impl
|
||||
self::gen::from_str_impl(f, section, list, is_exhaustive)?;
|
||||
writeln!(f)?;
|
||||
|
||||
writeln!(f, "}}")?;
|
||||
// Write the Serialize and Deserialize impls
|
||||
self::gen::serde_impl(f, section)?;
|
||||
writeln!(f)?;
|
||||
|
||||
// Write the JsonSchema impl
|
||||
self::gen::json_schema_impl(f, section, list)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
||||
Reference in New Issue
Block a user