Skip to content

Commit ff5ed29

Browse files
Modified the scripts to allow unfiltered SDK for testing (#552)
1 parent 953793a commit ff5ed29

5 files changed

Lines changed: 69 additions & 13 deletions

File tree

bin/generate-oas.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,26 @@
1212
exit(1);
1313
});
1414

15+
$testing = in_array('--testing', $argv, true);
16+
$language = 'en';
17+
foreach (array_slice($argv, 1) as $arg) {
18+
if ($arg[0] !== '-') {
19+
$language = $arg;
20+
break;
21+
}
22+
}
23+
1524
echo "\nCreating translated OpenAPI file ...\n";
16-
$language = $argv[1] ?? 'en';
1725
$generate = new Hello\OpenApi\Translate($language);
1826
$generate->run();
1927
$generate->printResults();
2028

2129
echo "\nCreating SDK-specific OpenAPI file ...\n";
2230
$generate = new Hello\OpenApi\GenerateSdkOas();
2331
$generate->run();
32+
33+
if ($testing) {
34+
echo "\nCreating testing SDK OpenAPI file (no hideOn filtering) ...\n";
35+
$generate = new Hello\OpenApi\GenerateSdkOas(true);
36+
$generate->run();
37+
}

build

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,19 @@
33
set -e
44

55
DIR=$(cd `dirname $0` && pwd)
6-
LANGUAGE="${1:-en}"
6+
LANGUAGE="en"
7+
TESTING=""
8+
9+
for arg in "$@"; do
10+
case $arg in
11+
--testing)
12+
TESTING="--testing"
13+
;;
14+
*)
15+
LANGUAGE="$arg"
16+
;;
17+
esac
18+
done
719

820
printf "Language chosen: ${LANGUAGE}\n"
921

@@ -12,7 +24,7 @@ mkdir -p "${DIR}/vendor"
1224
bash "${DIR}/bin/php" composer install
1325
printf "\n"
1426

15-
bash "${DIR}/bin/php" ./bin/generate-oas.php
27+
bash "${DIR}/bin/php" ./bin/generate-oas.php ${TESTING}
1628

1729
"${DIR}/bin/copy-examples-filtered" "${DIR}/examples" "${DIR}/sandbox/dotnet/src/Dropbox.SignSandbox" cs
1830
"${DIR}/bin/copy-examples-filtered" "${DIR}/examples" "${DIR}/sandbox/java/src/main/java/com/dropbox/sign_sandbox" java

generate-sdks

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@ DIR=$(cd `dirname $0` && pwd)
66
SDKS=( dotnet java-v1 java-v2 node php python ruby )
77
SHOW_HELP=0
88
TARGET_SDK=
9+
TESTING=0
910

10-
while getopts ":t:h" opt; do
11+
while getopts ":t:h-:" opt; do
1112
case $opt in
1213
t) TARGET_SDK="$OPTARG"
1314
;;
1415
h) SHOW_HELP=1
1516
;;
17+
-)
18+
case "${OPTARG}" in
19+
testing) TESTING=1
20+
;;
21+
*) echo "Invalid option --$OPTARG" >&2
22+
;;
23+
esac
24+
;;
1625
\?) echo "Invalid option -$OPTARG" >&2
1726
;;
1827
esac
@@ -55,8 +64,10 @@ Builds a given SDK into the sdks/[SDK] directory.
5564
be DELETED and REBUILT!
5665
5766
-t target SDK, "all", "dotnet", "java-v2", "java-v1", "node", "php", "python", "ruby"
67+
--testing use openapi-sdk-testing.yaml (includes all hideOn endpoints)
5868
-h display this help and exit
5969
Example: generate-sdks -t php
70+
Example: generate-sdks -t php --testing
6071
EOF
6172

6273
exit 0
@@ -140,9 +151,16 @@ function copy_oas()
140151
SDK="$1"
141152
SDK_DIR="${DIR}/sdks/${SDK}"
142153

143-
printf "Copying openapi-sdk.yaml ...\n"
154+
if [[ $TESTING -eq 1 ]]; then
155+
OAS_FILE="${DIR}/openapi-sdk-testing.yaml"
156+
printf "Copying openapi-sdk-testing.yaml ...\n"
157+
else
158+
OAS_FILE="${DIR}/openapi-sdk.yaml"
159+
printf "Copying openapi-sdk.yaml ...\n"
160+
fi
161+
144162
rm -f "${SDK_DIR}/openapi-sdk.yaml"
145-
cp -r "${DIR}/openapi-sdk.yaml" "${SDK_DIR}/openapi-sdk.yaml"
163+
cp -r "${OAS_FILE}" "${SDK_DIR}/openapi-sdk.yaml"
146164
}
147165

148166
function copy_examples()

src/Hello/OpenApi/GenerateSdkOas.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,31 @@ class GenerateSdkOas
1010

1111
private const SURFACE_ID = 'sdk';
1212

13+
private bool $testing;
14+
15+
public function __construct(bool $testing = false)
16+
{
17+
$this->testing = $testing;
18+
}
19+
1320
public function run(): void
1421
{
1522
$raw_file = new RawFile(self::ROOT_DIR . '/openapi-raw.yaml');
1623
$translation_file = self::ROOT_DIR . '/translations/en.yaml';
1724
$raw_file->translate(
1825
self::SURFACE_ID,
1926
$translation_file,
20-
$translation_file
27+
$translation_file,
28+
$this->testing
2129
);
2230

2331
$data = $raw_file->getData();
2432
unset($data['tags']);
2533
$raw_file->setData($data);
2634

27-
$raw_file->saveFile(self::ROOT_DIR . '/openapi-sdk.yaml');
35+
$output_file = $this->testing
36+
? self::ROOT_DIR . '/openapi-sdk-testing.yaml'
37+
: self::ROOT_DIR . '/openapi-sdk.yaml';
38+
$raw_file->saveFile($output_file);
2839
}
2940
}

src/Hello/OpenApi/RawFile.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,11 @@ public function __construct(string $filename)
6767
public function translate(
6868
string $surface_id,
6969
string $translation_file,
70-
string $fallback_file
70+
string $fallback_file,
71+
bool $skip_hide_on = false
7172
): void {
7273
$this->loadTranslations($translation_file, $fallback_file);
73-
$result = $this->recurse($this->openapi, $surface_id);
74+
$result = $this->recurse($this->openapi, $surface_id, $skip_hide_on);
7475

7576
$this->logs['translated'] = array_unique($this->logs['translated']);
7677
$this->logs['fallback'] = array_unique($this->logs['fallback']);
@@ -160,18 +161,18 @@ private function loadTranslations(string $file, string $fallback): void
160161
* searching for strings prepended with TRANSLATE_PREPEND and attempting
161162
* to translate them.
162163
*/
163-
private function recurse(array $data, string $surface_id): TranslationResult
164+
private function recurse(array $data, string $surface_id, bool $skip_hide_on = false): TranslationResult
164165
{
165166
$empty_by_hiding = false;
166167

167168
foreach ($data as $k => $v) {
168169
if (is_iterable($v)) {
169-
if (isset($v[self::HIDE_ON]) && $this->shouldHide($v[self::HIDE_ON], $surface_id)) {
170+
if (!$skip_hide_on && isset($v[self::HIDE_ON]) && $this->shouldHide($v[self::HIDE_ON], $surface_id)) {
170171
unset($data[$k]);
171172
$empty_by_hiding = empty($data);
172173
} else {
173174
unset($v[self::HIDE_ON]);
174-
$result = $this->recurse($v, $surface_id);
175+
$result = $this->recurse($v, $surface_id, $skip_hide_on);
175176
if ($result->isAllHidden()) {
176177
unset($data[$k]);
177178
} else {

0 commit comments

Comments
 (0)