diff --git a/bin/generate-oas.php b/bin/generate-oas.php index b4875ec75..81660d22d 100755 --- a/bin/generate-oas.php +++ b/bin/generate-oas.php @@ -12,8 +12,16 @@ exit(1); }); +$testing = in_array('--testing', $argv, true); +$language = 'en'; +foreach (array_slice($argv, 1) as $arg) { + if ($arg[0] !== '-') { + $language = $arg; + break; + } +} + echo "\nCreating translated OpenAPI file ...\n"; -$language = $argv[1] ?? 'en'; $generate = new Hello\OpenApi\Translate($language); $generate->run(); $generate->printResults(); @@ -21,3 +29,9 @@ echo "\nCreating SDK-specific OpenAPI file ...\n"; $generate = new Hello\OpenApi\GenerateSdkOas(); $generate->run(); + +if ($testing) { + echo "\nCreating testing SDK OpenAPI file (no hideOn filtering) ...\n"; + $generate = new Hello\OpenApi\GenerateSdkOas(true); + $generate->run(); +} diff --git a/build b/build index 470d514b3..836b0a91b 100755 --- a/build +++ b/build @@ -3,7 +3,19 @@ set -e DIR=$(cd `dirname $0` && pwd) -LANGUAGE="${1:-en}" +LANGUAGE="en" +TESTING="" + +for arg in "$@"; do + case $arg in + --testing) + TESTING="--testing" + ;; + *) + LANGUAGE="$arg" + ;; + esac +done printf "Language chosen: ${LANGUAGE}\n" @@ -12,7 +24,7 @@ mkdir -p "${DIR}/vendor" bash "${DIR}/bin/php" composer install printf "\n" -bash "${DIR}/bin/php" ./bin/generate-oas.php +bash "${DIR}/bin/php" ./bin/generate-oas.php ${TESTING} "${DIR}/bin/copy-examples-filtered" "${DIR}/examples" "${DIR}/sandbox/dotnet/src/Dropbox.SignSandbox" cs "${DIR}/bin/copy-examples-filtered" "${DIR}/examples" "${DIR}/sandbox/java/src/main/java/com/dropbox/sign_sandbox" java diff --git a/generate-sdks b/generate-sdks index 2fff0366b..bc44d86f8 100755 --- a/generate-sdks +++ b/generate-sdks @@ -6,13 +6,22 @@ DIR=$(cd `dirname $0` && pwd) SDKS=( dotnet java-v1 java-v2 node php python ruby ) SHOW_HELP=0 TARGET_SDK= +TESTING=0 -while getopts ":t:h" opt; do +while getopts ":t:h-:" opt; do case $opt in t) TARGET_SDK="$OPTARG" ;; h) SHOW_HELP=1 ;; + -) + case "${OPTARG}" in + testing) TESTING=1 + ;; + *) echo "Invalid option --$OPTARG" >&2 + ;; + esac + ;; \?) echo "Invalid option -$OPTARG" >&2 ;; esac @@ -55,8 +64,10 @@ Builds a given SDK into the sdks/[SDK] directory. be DELETED and REBUILT! -t target SDK, "all", "dotnet", "java-v2", "java-v1", "node", "php", "python", "ruby" +--testing use openapi-sdk-testing.yaml (includes all hideOn endpoints) -h display this help and exit Example: generate-sdks -t php +Example: generate-sdks -t php --testing EOF exit 0 @@ -140,9 +151,16 @@ function copy_oas() SDK="$1" SDK_DIR="${DIR}/sdks/${SDK}" - printf "Copying openapi-sdk.yaml ...\n" + if [[ $TESTING -eq 1 ]]; then + OAS_FILE="${DIR}/openapi-sdk-testing.yaml" + printf "Copying openapi-sdk-testing.yaml ...\n" + else + OAS_FILE="${DIR}/openapi-sdk.yaml" + printf "Copying openapi-sdk.yaml ...\n" + fi + rm -f "${SDK_DIR}/openapi-sdk.yaml" - cp -r "${DIR}/openapi-sdk.yaml" "${SDK_DIR}/openapi-sdk.yaml" + cp -r "${OAS_FILE}" "${SDK_DIR}/openapi-sdk.yaml" } function copy_examples() diff --git a/src/Hello/OpenApi/GenerateSdkOas.php b/src/Hello/OpenApi/GenerateSdkOas.php index d97f7b1b2..fd4b8db3a 100644 --- a/src/Hello/OpenApi/GenerateSdkOas.php +++ b/src/Hello/OpenApi/GenerateSdkOas.php @@ -10,6 +10,13 @@ class GenerateSdkOas private const SURFACE_ID = 'sdk'; + private bool $testing; + + public function __construct(bool $testing = false) + { + $this->testing = $testing; + } + public function run(): void { $raw_file = new RawFile(self::ROOT_DIR . '/openapi-raw.yaml'); @@ -17,13 +24,17 @@ public function run(): void $raw_file->translate( self::SURFACE_ID, $translation_file, - $translation_file + $translation_file, + $this->testing ); $data = $raw_file->getData(); unset($data['tags']); $raw_file->setData($data); - $raw_file->saveFile(self::ROOT_DIR . '/openapi-sdk.yaml'); + $output_file = $this->testing + ? self::ROOT_DIR . '/openapi-sdk-testing.yaml' + : self::ROOT_DIR . '/openapi-sdk.yaml'; + $raw_file->saveFile($output_file); } } diff --git a/src/Hello/OpenApi/RawFile.php b/src/Hello/OpenApi/RawFile.php index fcfa42cc3..04f57ef28 100644 --- a/src/Hello/OpenApi/RawFile.php +++ b/src/Hello/OpenApi/RawFile.php @@ -67,10 +67,11 @@ public function __construct(string $filename) public function translate( string $surface_id, string $translation_file, - string $fallback_file + string $fallback_file, + bool $skip_hide_on = false ): void { $this->loadTranslations($translation_file, $fallback_file); - $result = $this->recurse($this->openapi, $surface_id); + $result = $this->recurse($this->openapi, $surface_id, $skip_hide_on); $this->logs['translated'] = array_unique($this->logs['translated']); $this->logs['fallback'] = array_unique($this->logs['fallback']); @@ -160,18 +161,18 @@ private function loadTranslations(string $file, string $fallback): void * searching for strings prepended with TRANSLATE_PREPEND and attempting * to translate them. */ - private function recurse(array $data, string $surface_id): TranslationResult + private function recurse(array $data, string $surface_id, bool $skip_hide_on = false): TranslationResult { $empty_by_hiding = false; foreach ($data as $k => $v) { if (is_iterable($v)) { - if (isset($v[self::HIDE_ON]) && $this->shouldHide($v[self::HIDE_ON], $surface_id)) { + if (!$skip_hide_on && isset($v[self::HIDE_ON]) && $this->shouldHide($v[self::HIDE_ON], $surface_id)) { unset($data[$k]); $empty_by_hiding = empty($data); } else { unset($v[self::HIDE_ON]); - $result = $this->recurse($v, $surface_id); + $result = $this->recurse($v, $surface_id, $skip_hide_on); if ($result->isAllHidden()) { unset($data[$k]); } else {