From 8f4e64bc86c4de382ff367b7d3de9aa49d0227e9 Mon Sep 17 00:00:00 2001 From: Aleksandr Shushkov Date: Tue, 2 Aug 2022 10:28:05 +0300 Subject: [PATCH 1/4] Add multiple files generation optional flag --- xcode/build_phases/api_generator.sh | 37 +++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/xcode/build_phases/api_generator.sh b/xcode/build_phases/api_generator.sh index add9f89..8f01d96 100755 --- a/xcode/build_phases/api_generator.sh +++ b/xcode/build_phases/api_generator.sh @@ -3,6 +3,9 @@ # Description: # Generates API models & methods. # +# Optional flags: +# -m - generate api in multiple files +# # Parameters: # $1 - api generator version. # $2 - path to generated code directory @@ -29,6 +32,14 @@ readonly FALSE=1 readonly LOG_TAG="API-GENERATOR" +help() +{ + local HELP_MESSAGE="Flags: + -m - Generate multiple files api" + + echo "${HELP_MESSAGE}" +} + notice() { echo "${LOG_TAG}:NOTICE: ${1}" @@ -178,6 +189,8 @@ openapi_codegen() api_generator_codegen() { + local SINGLE_FILE="$1" + if [ -z "${API_SPEC_DIR}" ]; then if [ ! -v "${1}" ]; then local -r API_SPEC_DIR=${1} @@ -212,9 +225,29 @@ api_generator_codegen() . build-scripts/xcode/aux_scripts/download_file.sh ${FILE_NAME} ${DOWNLOAD_URL} - java -Xmx6g -jar "Downloads/${FILE_NAME}" generate-client-code --output-language SWIFT --specification-path ${API_SPEC_DIR} --output-path ${OUTPUT_PATH} --single-file true + java -Xmx6g -jar "Downloads/${FILE_NAME}" generate-client-code --output-language SWIFT --specification-path ${API_SPEC_DIR} --output-path ${OUTPUT_PATH} --single-file ${SINGLE_FILE} } +SINGLE_FILE=true + +while getopts "hm" OPTION; do + case "${OPTION}" in + h) + help + ;; + m) + notice "Multiple files option detected" + SINGLE_FILE=false # Defines -m flag to generate api with multiple files + ;; + ?) + notice "Unknown option -$OPTARG" + exit ${EXIT_FAILURE} + ;; + esac +done + +shift "$(($OPTIND -1))" # Remove the parsed options from positional params + readonly BUILD_PHASES_DIR=${SRCROOT}/build_phases mkdir -p ${BUILD_PHASES_DIR} @@ -247,7 +280,7 @@ readonly OPEN_API_SPEC_PATH=`find ${API_SPEC_DIR} -maxdepth 1 -name '*.yaml' -o if [ -f "${OPEN_API_SPEC_PATH}" ]; then openapi_codegen elif [ -f "${API_SPEC_DIR}/main.json" ]; then - api_generator_codegen + api_generator_codegen ${SINGLE_FILE} else notice "No api spec found!" exit ${EXIT_FAILURE} From fa8322b14228d786a59b4f131dec0b79fa67dd5f Mon Sep 17 00:00:00 2001 From: Aleksandr Shushkov Date: Tue, 2 Aug 2022 15:48:09 +0300 Subject: [PATCH 2/4] Change single file flag using --- xcode/build_phases/api_generator.sh | 55 ++++++++++------------------- 1 file changed, 19 insertions(+), 36 deletions(-) diff --git a/xcode/build_phases/api_generator.sh b/xcode/build_phases/api_generator.sh index 8f01d96..936b16b 100755 --- a/xcode/build_phases/api_generator.sh +++ b/xcode/build_phases/api_generator.sh @@ -3,9 +3,6 @@ # Description: # Generates API models & methods. # -# Optional flags: -# -m - generate api in multiple files -# # Parameters: # $1 - api generator version. # $2 - path to generated code directory @@ -32,14 +29,6 @@ readonly FALSE=1 readonly LOG_TAG="API-GENERATOR" -help() -{ - local HELP_MESSAGE="Flags: - -m - Generate multiple files api" - - echo "${HELP_MESSAGE}" -} - notice() { echo "${LOG_TAG}:NOTICE: ${1}" @@ -67,6 +56,22 @@ is_force_run() return ${FALSE} } +is_single_file() +{ + if [ -z "${SINGLE_FILE}" ]; then + echo "true" + return + fi + + local -r STR_MODE=`tr "[:upper:]" "[:lower:]" <<< ${SINGLE_FILE}` + + if [ ${STR_MODE} == "no" ] || [ ${STR_MODE} == "false" ] || [ ${STR_MODE} == "0" ]; then + echo "false" + else + echo "true" + fi +} + get_current_commit() { if [ -z "${API_SPEC_DIR}" ]; then @@ -189,8 +194,6 @@ openapi_codegen() api_generator_codegen() { - local SINGLE_FILE="$1" - if [ -z "${API_SPEC_DIR}" ]; then if [ ! -v "${1}" ]; then local -r API_SPEC_DIR=${1} @@ -224,30 +227,10 @@ api_generator_codegen() local -r DOWNLOAD_URL="https://maven.dev.touchin.ru/ru/touchin/api-generator/${VERSION}/${FILE_NAME}" . build-scripts/xcode/aux_scripts/download_file.sh ${FILE_NAME} ${DOWNLOAD_URL} - - java -Xmx6g -jar "Downloads/${FILE_NAME}" generate-client-code --output-language SWIFT --specification-path ${API_SPEC_DIR} --output-path ${OUTPUT_PATH} --single-file ${SINGLE_FILE} + notice $(is_single_file) + java -Xmx6g -jar "Downloads/${FILE_NAME}" generate-client-code --output-language SWIFT --specification-path ${API_SPEC_DIR} --output-path ${OUTPUT_PATH} --single-file $(is_single_file) } -SINGLE_FILE=true - -while getopts "hm" OPTION; do - case "${OPTION}" in - h) - help - ;; - m) - notice "Multiple files option detected" - SINGLE_FILE=false # Defines -m flag to generate api with multiple files - ;; - ?) - notice "Unknown option -$OPTARG" - exit ${EXIT_FAILURE} - ;; - esac -done - -shift "$(($OPTIND -1))" # Remove the parsed options from positional params - readonly BUILD_PHASES_DIR=${SRCROOT}/build_phases mkdir -p ${BUILD_PHASES_DIR} @@ -280,7 +263,7 @@ readonly OPEN_API_SPEC_PATH=`find ${API_SPEC_DIR} -maxdepth 1 -name '*.yaml' -o if [ -f "${OPEN_API_SPEC_PATH}" ]; then openapi_codegen elif [ -f "${API_SPEC_DIR}/main.json" ]; then - api_generator_codegen ${SINGLE_FILE} + api_generator_codegen else notice "No api spec found!" exit ${EXIT_FAILURE} From 021e4f410e06f21db233baf0b17c7135eca0e990 Mon Sep 17 00:00:00 2001 From: Aleksandr Shushkov Date: Tue, 2 Aug 2022 15:49:11 +0300 Subject: [PATCH 3/4] Removed rendundant notice --- xcode/build_phases/api_generator.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/xcode/build_phases/api_generator.sh b/xcode/build_phases/api_generator.sh index 936b16b..12818e1 100755 --- a/xcode/build_phases/api_generator.sh +++ b/xcode/build_phases/api_generator.sh @@ -227,7 +227,6 @@ api_generator_codegen() local -r DOWNLOAD_URL="https://maven.dev.touchin.ru/ru/touchin/api-generator/${VERSION}/${FILE_NAME}" . build-scripts/xcode/aux_scripts/download_file.sh ${FILE_NAME} ${DOWNLOAD_URL} - notice $(is_single_file) java -Xmx6g -jar "Downloads/${FILE_NAME}" generate-client-code --output-language SWIFT --specification-path ${API_SPEC_DIR} --output-path ${OUTPUT_PATH} --single-file $(is_single_file) } From 47a67edfff7593a6323f44d829aeb63d0d335153 Mon Sep 17 00:00:00 2001 From: Aleksandr Shushkov Date: Tue, 2 Aug 2022 15:50:52 +0300 Subject: [PATCH 4/4] Add emply line --- xcode/build_phases/api_generator.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/xcode/build_phases/api_generator.sh b/xcode/build_phases/api_generator.sh index 12818e1..c7e4a45 100755 --- a/xcode/build_phases/api_generator.sh +++ b/xcode/build_phases/api_generator.sh @@ -227,6 +227,7 @@ api_generator_codegen() local -r DOWNLOAD_URL="https://maven.dev.touchin.ru/ru/touchin/api-generator/${VERSION}/${FILE_NAME}" . build-scripts/xcode/aux_scripts/download_file.sh ${FILE_NAME} ${DOWNLOAD_URL} + java -Xmx6g -jar "Downloads/${FILE_NAME}" generate-client-code --output-language SWIFT --specification-path ${API_SPEC_DIR} --output-path ${OUTPUT_PATH} --single-file $(is_single_file) }