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
2 changes: 1 addition & 1 deletion graph-codegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ anyhow = "1.0.69"
bytes = "1"
derive_builder = "0.12.0"
from_as = "0.1"
Inflector = "0.11.4"
heck = "0.5"
lazy_static = "1.4.0"
rayon = "1.5.0"
regex = "1"
Expand Down
2 changes: 1 addition & 1 deletion graph-codegen/src/api_types/method_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::api_types::RequestTask;
use crate::parser::HttpMethod;
use crate::settings::{GeneratedMacroType, MethodMacroModifier};
use from_as::*;
use inflector::Inflector;
use heck::ToSnakeCase;
use std::io::{Read, Write};

/// Represents the macro used for describing requests. This is the outer
Expand Down
2 changes: 1 addition & 1 deletion graph-codegen/src/api_types/mod_file_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use from_as::*;
use graph_core::resource::ResourceIdentity;
use graph_error::{GraphFailure, GraphResult};
use graph_http::io_tools::create_dir;
use inflector::Inflector;
use heck::ToSnakeCase;
use std::collections::HashSet;
use std::fs::OpenOptions;
use std::io::{Read, Write};
Expand Down
12 changes: 6 additions & 6 deletions graph-codegen/src/api_types/request_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use crate::api_types::metadata_modifier::ModifierMap;
use crate::api_types::WriteConfiguration;
use crate::api_types::{Metadata, MetadataModifier, MethodMacro, RequestClientList, RequestTask};
use crate::filter::Filter;
use crate::inflector::Inflector;
use crate::macros::{MacroImplWriter, MacroQueueWriter};
use crate::openapi::{OpenApi, PathItem};
use crate::parser::HttpMethod;
use crate::traits::{FilterMetadata, RequestParser, INTERNAL_PATH_ID};
use from_as::*;
use graph_core::resource::ResourceIdentity;
use heck::{ToSnakeCase, ToUpperCamelCase};
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet, VecDeque};
use std::io::{Read, Write};
use std::str::FromStr;
Expand Down Expand Up @@ -75,16 +75,16 @@ impl RequestMetadata {
self.parent = format!("{resource_id_string}Id");
self.original_parent = resource_id_string;
} else {
self.parent = format!("{}Id", original_parent.to_pascal_case());
self.original_parent = original_parent.to_pascal_case();
self.parent = format!("{}Id", original_parent.to_upper_camel_case());
self.original_parent = original_parent.to_upper_camel_case();
self.resource_identity = ResourceIdentity::from_str(&self.original_parent).ok();
}
}

pub fn transform_secondary_request(&mut self, operation_mapping: &str, original_parent: &str) {
self.operation_mapping = operation_mapping.to_string();
self.parent = original_parent.to_pascal_case();
self.original_parent = original_parent.to_pascal_case();
self.parent = original_parent.to_upper_camel_case();
self.original_parent = original_parent.to_upper_camel_case();
self.resource_identity = ResourceIdentity::from_str(&self.original_parent).ok();
}

Expand Down Expand Up @@ -150,7 +150,7 @@ impl Metadata for RequestMetadata {
impl MetadataModifier for RequestMetadata {
fn replace_operation_mapping(&mut self, replacement: &str) {
self.operation_mapping = replacement.to_string();
self.parent = replacement.to_pascal_case();
self.parent = replacement.to_upper_camel_case();
}

fn replace_operation_id(&mut self, replacement: &str) {
Expand Down
2 changes: 1 addition & 1 deletion graph-codegen/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![recursion_limit = "1024"]
#![allow(deprecated)]
pub extern crate inflector;
pub extern crate heck;
#[macro_use]
extern crate derive_builder;
#[macro_use]
Expand Down
12 changes: 6 additions & 6 deletions graph-codegen/src/macros/macro_queue_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use crate::api_types::{
RequestTask,
};
use crate::api_types::{ModWriteConfiguration, WriteConfiguration};
use crate::inflector::Inflector;
use crate::openapi::OpenApi;
use crate::settings::{get_method_macro_modifiers, ResourceSettings};
use anyhow::anyhow;
use bytes::{BufMut, BytesMut};
use from_as::*;
use graph_core::resource::ResourceIdentity;
use graph_http::io_tools::create_dir;
use heck::{ToLowerCamelCase, ToSnakeCase, ToUpperCamelCase};
use std::collections::{BTreeMap, BTreeSet, HashSet, VecDeque};
use std::fmt::Debug;
use std::fmt::Write as _;
Expand Down Expand Up @@ -360,9 +360,9 @@ pub trait MacroImplWriter {
let ris: VecDeque<(String, ResourceIdentity)> = keys
.iter()
.map(|key| {
let key_id = key.to_pascal_case();
let key_id = key.to_upper_camel_case();
if key_id.ends_with("Id") {
let key_id_stripped = key.to_camel_case()[..key.len() - 2].to_string();
let key_id_stripped = key.to_lower_camel_case()[..key.len() - 2].to_string();
(
key_id.clone(),
ResourceIdentity::from_str(key_id_stripped.as_str())
Expand All @@ -371,7 +371,7 @@ pub trait MacroImplWriter {
} else {
(
key_id.clone(),
ResourceIdentity::from_str(&key.to_camel_case())
ResourceIdentity::from_str(&key.to_lower_camel_case())
.unwrap_or_else(|_| panic!("Unable to find variant for {key_id}")),
)
}
Expand Down Expand Up @@ -402,13 +402,13 @@ pub trait MacroImplWriter {

let client_names: Vec<String> = keys
.iter()
.map(|name| format!("{}ApiClient", name.to_pascal_case()))
.map(|name| format!("{}ApiClient", name.to_upper_camel_case()))
.collect();

// Build ApiClientLink enum to add the client being generated as a method link from one client
// to another. This is for ease of use and doesnt always work for ever client name.
for (name, _) in ris.iter() {
let client_name = format!("{}ApiClient", name.to_pascal_case());
let client_name = format!("{}ApiClient", name.to_upper_camel_case());
if client_name.contains("Id") {
let mut method_name = name.to_snake_case();
if method_name.ends_with("s_id") && !method_name.ends_with("es_id") {
Expand Down
4 changes: 2 additions & 2 deletions graph-codegen/src/openapi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ use crate::traits::RequestParser;
use from_as::*;
use graph_error::GraphFailure;
use graph_http::url::GraphUrl;
use inflector::Inflector;
use heck::ToUpperCamelCase;
use rayon::prelude::*;
use reqwest::Url;
use serde_json::Value;
Expand Down Expand Up @@ -305,7 +305,7 @@ impl OpenApi {
.map(|(path, _path_item)| {
path.split('/')
.filter(|s| !s.trim().is_empty())
.map(|s| s.to_pascal_case())
.map(|s| s.to_upper_camel_case())
.take(1)
.collect()
})
Expand Down
12 changes: 8 additions & 4 deletions graph-codegen/src/openapi/operation.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::api_types::RequestMetadata;
use crate::inflector::Inflector;
use crate::parser::HttpMethod;
use crate::{
openapi::{
Expand All @@ -10,6 +9,7 @@ use crate::{
};
use from_as::*;
use graph_core::resource::ResourceIdentity;
use heck::{ToLowerCamelCase, ToUpperCamelCase};
use std::str::FromStr;
use std::{
collections::{HashMap, VecDeque},
Expand Down Expand Up @@ -158,13 +158,17 @@ impl Operation {

if operation_mapping.contains('.') {
let v: Vec<&str> = operation_mapping.split('.').collect();
parent = v.last().map(|s| s.to_pascal_case()).unwrap_or_default();
parent = v
.last()
.map(|s| s.to_upper_camel_case())
.unwrap_or_default();
} else {
parent = operation_mapping.to_pascal_case();
parent = operation_mapping.to_upper_camel_case();
}

let original_parent = parent.clone();
let resource_identity = ResourceIdentity::from_str(&original_parent.to_camel_case()).ok();
let resource_identity =
ResourceIdentity::from_str(&original_parent.to_lower_camel_case()).ok();

RequestMetadata {
has_body: self.has_body(),
Expand Down
2 changes: 1 addition & 1 deletion graph-codegen/src/openapi/path_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::openapi::{EitherT, Operation, Parameter, Reference, Server};
use crate::parser::HttpMethod;
use crate::traits::{PathMatcher, RequestParser};
use from_as::*;
use inflector::Inflector;
use heck::ToSnakeCase;
use std::collections::{HashMap, HashSet};
use std::{
collections::VecDeque,
Expand Down
4 changes: 2 additions & 2 deletions graph-codegen/src/parser/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{
traits::{HashMapExt, RequestParser},
};
use from_as::*;
use inflector::Inflector;
use heck::ToLowerCamelCase;
use std::{
collections::{
hash_set::{Difference, Iter},
Expand Down Expand Up @@ -366,7 +366,7 @@ impl RequestSet {
vec.retain(|s| !s.is_empty());
if let Some(name) = vec.pop_front() {
if !name.is_empty() {
names.push(name.to_camel_case());
names.push(name.to_lower_camel_case());
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions graph-codegen/src/parser/resource.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::parser::RequestSet;
use from_as::*;
use inflector::Inflector;
use heck::ToLowerCamelCase;
use std::{
collections::{BTreeSet, HashMap, VecDeque},
convert::TryFrom,
Expand All @@ -23,7 +23,7 @@ impl ResourceNames {

pub fn sort(&mut self) {
let mut v: Vec<String> = self.to_vec();
v = v.iter().map(|s| s.to_camel_case()).collect();
v = v.iter().map(|s| s.to_lower_camel_case()).collect();
v.sort();
self.names = v.into_iter().collect();
}
Expand All @@ -39,7 +39,7 @@ impl From<Vec<String>> for ResourceNames {
vec.retain(|s| !s.is_empty());
if let Some(name) = vec.pop_front() {
if !name.is_empty() {
names.push(name.to_camel_case());
names.push(name.to_lower_camel_case());
}
}
}
Expand Down Expand Up @@ -73,7 +73,7 @@ impl From<HashMap<String, RequestSet>> for ResourceNames {
fn from(map: HashMap<String, RequestSet>) -> Self {
let mut resource_names = ResourceNames::default();
for (name, _request_set) in map.iter() {
resource_names.names.insert(name.to_camel_case());
resource_names.names.insert(name.to_lower_camel_case());
}
resource_names
}
Expand Down
6 changes: 3 additions & 3 deletions graph-codegen/src/traits/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::parser::error::ParseError;
use crate::parser::{HttpMethod, Request};
use crate::traits::HashMapExt;
use from_as::*;
use inflector::Inflector;
use heck::{ToSnakeCase, ToUpperCamelCase};
use regex::Regex;
use std::collections::{HashMap, HashSet, VecDeque};
use std::io::{Read, Write};
Expand Down Expand Up @@ -511,9 +511,9 @@ impl RequestParser for &str {
vec.retain(|l| !l.is_empty());
let first = vec.pop_front().unwrap();
let last = vec.pop_front().unwrap();
map.entry_modify_insert(first.to_pascal_case(), last.to_pascal_case());
map.entry_modify_insert(first.to_upper_camel_case(), last.to_upper_camel_case());
} else {
map.insert(link.to_pascal_case(), vec![]);
map.insert(link.to_upper_camel_case(), vec![]);
}
}

Expand Down
2 changes: 1 addition & 1 deletion graph-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ homepage = "https://github.com/sreeise/graph-rs-sdk"
async-trait = "0.1.35"
base64 = "0.21.0"
dyn-clone = "1.0.14"
Inflector = "0.11.4"
heck = "0.5"
http = { workspace = true }
jsonwebtoken = "9.1.0"
parking_lot = "0.12.1"
Expand Down
10 changes: 5 additions & 5 deletions graph-core/src/resource/resource_identity.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::fmt::Display;
use inflector::Inflector;
use heck::{ToLowerCamelCase, ToSnakeCase, ToUpperCamelCase};

/// Comprises both top level and second level resources.
/// These are not generated from OpenApi, except for top level resources,
Expand Down Expand Up @@ -409,7 +409,7 @@ impl Display for ResourceIdentity {
ResourceIdentity::DevicesRegisteredUsers => "registeredUsers".into(),
ResourceIdentity::Custom => "".into(),

_ => self.as_ref().to_camel_case(),
_ => self.as_ref().to_lower_camel_case(),
};
write!(f, "{}", str)
}
Expand All @@ -429,11 +429,11 @@ impl ResourceIdentity {
}

pub fn exact_camel_case(&self) -> String {
self.as_ref().to_camel_case()
self.as_ref().to_lower_camel_case()
}

pub fn exact_pascal_case(&self) -> String {
self.as_ref().to_pascal_case()
self.as_ref().to_upper_camel_case()
}

pub fn exact_snake_case(&self) -> String {
Expand Down Expand Up @@ -533,6 +533,6 @@ pub enum TopLevelResource {

impl Display for TopLevelResource {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.as_ref().to_camel_case())
write!(f, "{}", self.as_ref().to_lower_camel_case())
}
}
Loading