1
0
mirror of https://github.com/matrix-org/matrix-authentication-service.git synced 2025-07-29 22:01:14 +03:00

Use iana generated types in more places

This commit is contained in:
Quentin Gliech
2022-01-12 12:22:54 +01:00
parent 2844706bb1
commit 5b9c35a079
20 changed files with 222 additions and 211 deletions

View File

@ -182,10 +182,12 @@ async fn generate_oauth(client: &Arc<Client>, path: PathBuf) -> anyhow::Result<(
"https://www.iana.org/assignments/jose/jose.xhtml",
client.clone(),
)
.load::<TokenTypeHint>()
.load::<AccessTokenType>()
.await?
.load::<AuthorizationEndpointResponseType>()
.await?
.load::<TokenTypeHint>()
.await?
.load::<TokenEndpointAuthenticationMethod>()
.await?
.load::<PkceCodeChallengeMethod>()

View File

@ -21,22 +21,25 @@ use crate::{
#[allow(dead_code)]
#[derive(Debug, Deserialize)]
pub struct TokenTypeHint {
#[serde(rename = "Hint Value")]
pub struct AccessTokenType {
#[serde(rename = "Name")]
name: String,
#[serde(rename = "Additional Token Endpoint Response Parameters")]
additional_parameters: String,
#[serde(rename = "HTTP Authentication Scheme(s)")]
http_schemes: String,
#[serde(rename = "Change Controller")]
change_controller: String,
#[serde(rename = "Reference")]
reference: String,
}
impl EnumEntry for TokenTypeHint {
const URL: &'static str =
"https://www.iana.org/assignments/oauth-parameters/token-type-hint.csv";
const SECTIONS: &'static [Section] = &[s("OAuthTokenTypeHint", "OAuth Token Type Hint")];
impl EnumEntry for AccessTokenType {
const URL: &'static str = "https://www.iana.org/assignments/oauth-parameters/token-types.csv";
const SECTIONS: &'static [Section] = &[s("OAuthAccessTokenType", "OAuth Access Token Type")];
fn key(&self) -> Option<&'static str> {
Some("OAuthTokenTypeHint")
Some("OAuthAccessTokenType")
}
fn name(&self) -> &str {
@ -82,16 +85,41 @@ pub struct TokenEndpointAuthenticationMethod {
reference: String,
}
#[allow(dead_code)]
#[derive(Debug, Deserialize)]
pub struct TokenTypeHint {
#[serde(rename = "Hint Value")]
name: String,
#[serde(rename = "Change Controller")]
change_controller: String,
#[serde(rename = "Reference")]
reference: String,
}
impl EnumEntry for TokenTypeHint {
const URL: &'static str =
"https://www.iana.org/assignments/oauth-parameters/token-type-hint.csv";
const SECTIONS: &'static [Section] = &[s("OAuthTokenTypeHint", "OAuth Token Type Hint")];
fn key(&self) -> Option<&'static str> {
Some("OAuthTokenTypeHint")
}
fn name(&self) -> &str {
&self.name
}
}
impl EnumEntry for TokenEndpointAuthenticationMethod {
const URL: &'static str =
"https://www.iana.org/assignments/oauth-parameters/token-endpoint-auth-method.csv";
const SECTIONS: &'static [Section] = &[s(
"OAuthTokenEndpointAuthenticationMethod",
"OAuthClientAuthenticationMethod",
"OAuth Token Endpoint Authentication Method",
)];
fn key(&self) -> Option<&'static str> {
Some("OAuthTokenEndpointAuthenticationMethod")
Some("OAuthClientAuthenticationMethod")
}
fn name(&self) -> &str {

View File

@ -61,7 +61,11 @@ pub trait EnumEntry: DeserializeOwned + Send + Sync {
None
}
fn enum_name(&self) -> String {
self.name().replace('+', "_").to_case(Case::Pascal)
// Do the case transformation twice to have "N_A" turned to "Na" instead of "NA"
self.name()
.replace('+', "_")
.to_case(Case::Pascal)
.to_case(Case::Pascal)
}
async fn fetch(client: &Client) -> anyhow::Result<Vec<(&'static str, EnumMember)>> {