Skip to content

Commit

Permalink
Merge pull request #41 from kudlatyamroth/bugfix/correct-operation-names
Browse files Browse the repository at this point in the history
fix: proper operation names from endpoint path
  • Loading branch information
kstasik authored Sep 9, 2021
2 parents b0e66e2 + 551ca92 commit 5336be6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 22 deletions.
24 changes: 7 additions & 17 deletions src/process/name/endpoint.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::word::{is_plurar, normalize, pluralize, singularize};
use super::word::{is_plurar, pluralize, singularize};

use crate::error::Error;
use inflector::Inflector;
use regex::Regex;

pub struct Endpoint {
Expand Down Expand Up @@ -86,7 +87,7 @@ impl Endpoint {

let mut resources: Vec<String> = vec![];
for (i, resource) in self.resources.iter().enumerate() {
let processed = normalize(&resource.clone());
let processed = resource.clone().to_camel_case();

resources.push(
{
Expand Down Expand Up @@ -116,20 +117,9 @@ impl Endpoint {
// camelcase
parts
.into_iter()
.enumerate()
.map(|(i, mut s)| {
if i == 0 {
return s;
}

if let Some(first) = s.get_mut(0..1) {
first.make_ascii_uppercase();
}

s
})
.collect::<Vec<String>>()
.join("")
.join(" ")
.to_camel_case()
}
}

Expand All @@ -150,7 +140,7 @@ mod tests {
#[test_case( "get".to_string(), "v2/users/{id}".to_string(), "v2GetUser".to_string(); "endpoint name test 10" )]
#[test_case( "get".to_string(), "v1/users/{id}/status".to_string(), "v1GetUserStatus".to_string(); "endpoint name test 11" )]
#[test_case( "post".to_string(), "users/{id}/groups".to_string(), "createUserGroup".to_string(); "endpoint name test 12" )]
#[test_case( "get".to_string(), "user-groups/{id}".to_string(), "getUsergroup".to_string(); "endpoint name test 13" )]
#[test_case( "get".to_string(), "user-groups/{id}".to_string(), "getUserGroup".to_string(); "endpoint name test 13" )]
#[test_case( "get".to_string(), "v1/users/{id}/statuses".to_string(), "v1ListUserStatuses".to_string(); "endpoint name test 14" )]
fn test_operation_name(method: String, path: String, expected: String) {
assert_eq!(
Expand All @@ -168,7 +158,7 @@ mod tests {
);
}

#[test_case( "get".to_string(), "user-groups/{id}".to_string(), "usergroupGet".to_string(); "endpoint name reverse test 1" )]
#[test_case( "get".to_string(), "user-groups/{id}".to_string(), "userGroupGet".to_string(); "endpoint name reverse test 1" )]
#[test_case( "get".to_string(), "v1/users/{id}/statuses".to_string(), "userStatusesListV1".to_string(); "endpoint name reverse test 2" )]
fn test_operation_name_reverse(method: String, path: String, expected: String) {
assert_eq!(
Expand Down
5 changes: 0 additions & 5 deletions src/process/name/word.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ pub fn pluralize(word: String) -> String {
word
}

// todo: ...
pub fn normalize(method: &str) -> String {
method.replace("-", "")
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down

0 comments on commit 5336be6

Please sign in to comment.