Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions codegen/src/client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use heck::{ToSnakeCase, ToUpperCamelCase};
use openapiv3::OpenAPI;
use proc_macro2::{Ident, Span};
use quote::quote;
use std::collections::HashMap;
Expand All @@ -9,6 +10,7 @@ use crate::TagSchemas;
/// Writes the top-level API client file and tag accessors to the output directory.
pub fn generate_client_file(
out_path: &Path,
spec: &OpenAPI,
tag_schemas: &HashMap<String, TagSchemas>,
) -> Result<(), String> {
let mut client_path = out_path.to_path_buf();
Expand All @@ -18,6 +20,15 @@ pub fn generate_client_file(
let mut sorted_tags: Vec<_> = tag_schemas.keys().collect();
sorted_tags.sort();

// Build a map of tag names to their deprecation notices
let mut tag_deprecations: HashMap<String, String> = HashMap::new();
for tag in &spec.tags {
if let Some(serde_json::Value::String(notice)) = tag.extensions.get("x-deprecation-notice")
{
tag_deprecations.insert(tag.name.clone(), notice.clone());
}
}

// Generate accessor methods for each tag client
let mut tag_methods = Vec::new();
for tag in sorted_tags {
Expand All @@ -29,7 +40,16 @@ pub fn generate_client_file(
Span::call_site(),
);

let deprecation_attr = if let Some(notice) = tag_deprecations.get(tag.as_str()) {
quote! {
#[deprecated = #notice]
}
} else {
quote! {}
};

tag_methods.push(quote! {
#deprecation_attr
pub fn #method_name(&self) -> crate::resources::#client_module::#client_type<'_> {
crate::resources::#client_module::#client_type::new(self)
}
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ impl Generator {

fn generate_client_module(&self) -> Result<(), String> {
Self::log("[generate sdk] generating client.rs ...");
generate_client_file(&self.out_path, &self.schemas_by_tag.tag_schemas)
generate_client_file(&self.out_path, &self.spec, &self.schemas_by_tag.tag_schemas)
}

fn generate_mod_rs(&self) -> Result<(), String> {
Expand Down
1 change: 1 addition & 0 deletions sdk/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl Client {
pub fn roles(&self) -> crate::resources::roles::RolesClient<'_> {
crate::resources::roles::RolesClient::new(self)
}
#[deprecated = "Subaccounts API is deprecated, please use [Members](https://developer.sumup.com/api/members) API instead to manage your account members."]
pub fn subaccounts(&self) -> crate::resources::subaccounts::SubaccountsClient<'_> {
crate::resources::subaccounts::SubaccountsClient::new(self)
}
Expand Down