Skip to content

Commit

Permalink
Replace bash expansion with tr (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
vicentepinto98 authored Sep 18, 2023
1 parent 10d1f52 commit 8ab3c18
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions scripts/generate-sdk/generate-sdk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,22 @@ for service_json in ${ROOT_DIR}/oas/*.json; do
service="${service%.json}"

# Remove invalid characters to ensure a valid Go pkg name
service="${service//-/}" # remove dashes
service="${service// /}" # remove empty spaces
service="${service//_/}" # remove underscores
service="${service,,}" # convert upper case letters to lower case
service=$(echo "${service}" | tr -d -c '[:alnum:]') # remove non-alphanumeric characters
service="${service//-/}" # remove dashes
service="${service// /}" # remove empty spaces
service="${service//_/}" # remove underscores
service=$(echo "${service}" | tr '[:upper:]' '[:lower:]') # convert upper case letters to lower case
service=$(echo "${service}" | tr -d -c '[:alnum:]') # remove non-alphanumeric characters

go_pkg_name_format="^[a-z0-9]+$"
if [[ ! ${service} =~ ${go_pkg_name_format} ]]; # check that it is a single lower case word
then
if [[ ! ${service} =~ ${go_pkg_name_format} ]]; then # check that it is a single lower case word
echo "Service ${service} has an invalid Go package name even after removing invalid characters. The generate-sdk.sh script might need to be updated to catch corner case, contact the repo maintainers."
exit 1
exit 1
fi

contains_empty_space_pattern=" |'"
if [[ ${service_json} =~ ${contains_empty_space_pattern} ]];
then
if [[ ${service_json} =~ ${contains_empty_space_pattern} ]]; then
echo "OAS filename ${service_json} has empty spaces, the generation will fail. If the OAS was downloaded using the make download-oas command, it should be fixed in the api-specifications repo, please contact the repo maintainers at ${OAS_REPO}."
exit 1
exit 1
fi

echo "Generating ${service} service..."
Expand Down

0 comments on commit 8ab3c18

Please sign in to comment.