Skip to content

Commit

Permalink
prepare for keycloak 26.0.2 organizations
Browse files Browse the repository at this point in the history
  • Loading branch information
kilork committed Oct 29, 2024
1 parent 67b41ab commit 69776bf
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 13 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ rc-map = ["serde/rc"]
rc-str = ["serde/rc"]
rc-val = ["serde/rc"]
rc-vec = ["serde/rc"]
tags-all = ["tag-attack-detection", "tag-authentication-management", "tag-client-attribute-certificate", "tag-client-initial-access", "tag-client-registration-policy", "tag-client-role-mappings", "tag-client-scopes", "tag-clients", "tag-component", "tag-groups", "tag-identity-providers", "tag-key", "tag-protocol-mappers", "tag-realms-admin", "tag-role-mapper", "tag-roles", "tag-roles-by-id", "tag-scope-mappings", "tag-users"]
tags-all = ["tag-attack-detection", "tag-authentication-management", "tag-client-attribute-certificate", "tag-client-initial-access", "tag-client-registration-policy", "tag-client-role-mappings", "tag-client-scopes", "tag-clients", "tag-component", "tag-groups", "tag-identity-providers", "tag-key", "tag-organizations", "tag-protocol-mappers", "tag-realms-admin", "tag-role-mapper", "tag-roles", "tag-roles-by-id", "tag-scope-mappings", "tag-users"]
tag-attack-detection = []
tag-authentication-management = []
tag-client-attribute-certificate = []
Expand All @@ -34,6 +34,7 @@ tag-component = []
tag-groups = []
tag-identity-providers = []
tag-key = []
tag-organizations = []
tag-protocol-mappers = []
tag-realms-admin = []
tag-role-mapper = []
Expand Down
43 changes: 31 additions & 12 deletions examples/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ enum Cli {
const RESERVED_WORDS: &[&str] = &["type", "self", "static", "use"];

mod openapi {
use std::{borrow::Cow, fmt::Display, str::FromStr, sync::Arc};
use std::{borrow::Cow, collections::HashSet, fmt::Display, str::FromStr, sync::Arc};

use heck::{ToLowerCamelCase, ToSnakeCase, ToUpperCamelCase};
use indexmap::IndexMap;
Expand Down Expand Up @@ -133,12 +133,17 @@ mod openapi {
self.0.get(&ContentType::ApplicationOctetStream)
}

fn as_html_form(&self) -> Option<&ContentSchema> {
self.0.get(&ContentType::HtmlForm)
}

fn as_any(&self) -> Option<&ContentSchema> {
self.0.get(&ContentType::Any)
}

fn as_content_schema(&self) -> Option<&ContentSchema> {
self.as_json()
.or(self.as_html_form())
.or(self.as_text_plain())
.or(self.as_binary_text())
.or(self.as_any())
Expand All @@ -158,6 +163,7 @@ mod openapi {
self.as_json()
.map(|_| format!("json(&{body_name})"))
.or(self.as_text_plain().map(|_| format!("body({body_name})")))
.or(self.as_html_form().map(|_| format!("form(&{body_name})")))
}

fn to_rust_reqwest_parse_body_call(&self) -> Option<(Cow<'_, str>, Option<Cow<'_, str>>)> {
Expand All @@ -169,6 +175,7 @@ mod openapi {
.or(self.as_text_plain())
.map(|_| ("text", Some(".map(From::from)"))))
.or(self.as_binary_blob().map(|_| ("bytes", None)))
.or(self.as_html_form().map(|_| ("form", None)))
.map(|(method, conv)| (method.into(), conv.map(From::from)))
}
}
Expand All @@ -195,6 +202,7 @@ mod openapi {
#[derive(Debug, Deserialize)]
struct Responses(IndexMap<String, Response>);

#[derive(Debug)]
struct ReturnType<'rt> {
value: Cow<'rt, str>,
body: Option<Cow<'rt, str>>,
Expand Down Expand Up @@ -701,7 +709,7 @@ mod openapi {
}
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, PartialEq, Eq, Hash)]
#[serde(untagged)]
pub enum ObjectSchema<P> {
Struct(SchemaStruct<P>),
Expand Down Expand Up @@ -736,11 +744,17 @@ mod openapi {
}
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, PartialEq, Eq)]
pub struct SchemaStruct<P> {
pub properties: IndexMap<String, P>,
}

impl<P: std::hash::Hash> std::hash::Hash for SchemaStruct<P> {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.properties.as_slice().hash(state);
}
}

impl SchemaStruct<Property> {
fn to_rust_type_definition(&self, name: &str, ref_mode: RefMode) -> String {
let mut fields = self
Expand Down Expand Up @@ -844,12 +858,17 @@ pub struct {name} {{
}

impl SchemaStruct<Kind> {
fn to_rust_type(&self, _: RefMode) -> Cow<str> {
todo!()
fn to_rust_type(&self, ref_mode: RefMode) -> Cow<str> {
let property_types: HashSet<&Kind> = self.properties.values().collect();
let property_type = match property_types.into_iter().collect::<Vec<_>>().as_slice() {
&[property_type_kind] => property_type_kind.to_rust_type(ref_mode),
_ => "Value".into(),
};
format!("TypeMap<String, {property_type}>",).into()
}
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "camelCase")]
pub struct SchemaMap<P> {
pub additional_properties: P,
Expand All @@ -874,7 +893,7 @@ pub struct {name} {{
}
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "camelCase")]
pub struct SchemaAllOf<P> {
pub all_of: Vec<P>,
Expand Down Expand Up @@ -932,7 +951,7 @@ pub enum {name} {{
Std,
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, PartialEq, Eq, Hash)]
#[serde(untagged)]
pub enum Kind {
Generic(Generic),
Expand Down Expand Up @@ -999,7 +1018,7 @@ pub enum {name} {{
}
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, PartialEq, Eq, Hash)]
pub struct Property {
#[serde(default)]
deprecated: bool,
Expand All @@ -1024,7 +1043,7 @@ pub enum {name} {{
}
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "lowercase", tag = "type")]
pub enum Generic {
Array {
Expand All @@ -1040,13 +1059,13 @@ pub enum {name} {{
String,
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, PartialEq, Eq, Hash)]
pub struct Ref {
#[serde(rename = "$ref")]
pub reference: String,
}

#[derive(Debug, Deserialize)]
#[derive(Debug, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "lowercase")]
pub enum IntegerFormat {
Int32,
Expand Down

0 comments on commit 69776bf

Please sign in to comment.