Skip to content

Commit

Permalink
added tags
Browse files Browse the repository at this point in the history
  • Loading branch information
kilork committed Mar 23, 2024
1 parent 8ee5f04 commit 73b0582
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
22 changes: 21 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,33 @@ repository = "https://github.com/kilork/keycloak"
rust-version = "1.58"

[features]
default = ["rc"]
default = ["rc", "tags-all"]
schemars = ["dep:schemars"]
rc = ["rc-map", "rc-str", "rc-val", "rc-vec"]
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"]
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 = []

[dependencies]
reqwest = { version = "0.12", default-features = false, features = ["json"] }
Expand Down
28 changes: 27 additions & 1 deletion examples/openapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ enum Cli {
Rest,
/// Specs
Specs,
/// Tags
Tags,
}

const RESERVED_WORDS: &[&str] = &["type", "self", "static", "use"];
Expand Down Expand Up @@ -305,7 +307,7 @@ mod openapi {
);
}
if let [tag] = self.tags.as_slice() {
comments.push(vec![format!("Resource: `{}`", tag).into()]);
comments.push(vec![format!("Resource: `{tag}`").into()]);
}
comments.push(vec![format!(
"`{} {path_snake_case}`",
Expand Down Expand Up @@ -359,6 +361,12 @@ mod openapi {

output.extend(comments);

if let [tag] = self.tags.as_slice() {
use heck::ToKebabCase;
let tag = tag.to_kebab_case();
output.push(format!(r#"#[cfg(feature = "tag-{tag}")]"#));
}

if self.deprecated {
output.push("#[deprecated]".into());
}
Expand Down Expand Up @@ -903,6 +911,7 @@ fn main() {
match cli {
Cli::Types => generate_types(&specs),
Cli::Rest => generate_rest(&specs),
Cli::Tags => list_tags(&specs),
Cli::Specs => {
println!("{specs:#?}");
}
Expand Down Expand Up @@ -991,3 +1000,20 @@ pub type TypeVec<I> = Arc<[I]>;"###
);
}
}

fn list_tags(spec: &openapi::Spec) {
use heck::ToKebabCase;
let tags = spec
.tags
.iter()
.map(|tag| "tag-".to_string() + tag.name.to_kebab_case().as_str())
.collect::<Vec<_>>();
println!(
"tags-all = [{}]",
tags.iter()
.map(|tag| format!("{tag:?}"))
.collect::<Vec<_>>()
.join(", ")
);
tags.iter().for_each(|line| println!("{line} = []"));
}

0 comments on commit 73b0582

Please sign in to comment.