|
12 | 12 | * |
13 | 13 | * @param string $path The path to the schema file |
14 | 14 | * @param string $category The category code for the schema |
15 | | - * @param string $name The human-readable API name for the schema |
| 15 | + * @param string $country The country code for the schema |
| 16 | + * @param string $apiCode The internal API code for the schema |
| 17 | + * @param string $apiName The human-readable API name for the schema |
16 | 18 | * @return void |
17 | 19 | */ |
18 | | -function customizeSchema(string $path, string $category, string $name): void |
19 | | -{ |
| 20 | +function customizeSchema( |
| 21 | + string $path, |
| 22 | + string $category, |
| 23 | + string $country, |
| 24 | + string $apiCode, |
| 25 | + string $apiName |
| 26 | +): void { |
20 | 27 | // There are auth headers that are the same on (nearly) every request, but which Walmart includes in every |
21 | 28 | // single request schema. We remove them so that the SDK is easier to use, and will pass them in during the |
22 | 29 | // request signing process when an endpoint is called. |
@@ -78,7 +85,7 @@ function customizeSchema(string $path, string $category, string $name): void |
78 | 85 | $security = []; |
79 | 86 |
|
80 | 87 | // Standardize tags based on our internal naming convention (derived from resources/apis.json) |
81 | | - $verb['tags'] = [$name]; |
| 88 | + $verb['tags'] = [$apiName]; |
82 | 89 |
|
83 | 90 | // Update each operation's parameters and auth information |
84 | 91 | foreach ($verb['parameters'] as $i => $parameter) { |
@@ -176,6 +183,8 @@ function customizeSchema(string $path, string $category, string $name): void |
176 | 183 | $schema['components']['schemas'] = replaceComponentInlineSchemas($componentSchemas); |
177 | 184 | } |
178 | 185 |
|
| 186 | + $schema = fixSchema($schema, $country, $category, $apiCode); |
| 187 | + |
179 | 188 | file_put_contents($path, json_encode($schema, JSON_PRETTY_PRINT)); |
180 | 189 | } |
181 | 190 |
|
@@ -345,14 +354,43 @@ function chooseContentType(array $content): string |
345 | 354 | return array_key_first($content); |
346 | 355 | } |
347 | 356 |
|
| 357 | +/** |
| 358 | + * Applies specific model fixes from the resources/schema-corrections.json file to the current schema. |
| 359 | + * |
| 360 | + * @param array $schema The schema to apply the fixes to |
| 361 | + * @param string $country The country code for the schema |
| 362 | + * @param string $category The category code for the schema |
| 363 | + * @param string $code The internal API code for the schema |
| 364 | + */ |
| 365 | +function fixSchema(array $schema, string $country, string $category, string $code): array |
| 366 | +{ |
| 367 | + $allFixes = json_decode(file_get_contents(SCHEMA_FIXES_FILE), true); |
| 368 | + $fixes = $allFixes[$country][$category][$code] ?? []; |
| 369 | + |
| 370 | + if (isset($fixes['paths'])) { |
| 371 | + $schema['paths'] = array_merge_recursive_distinct( |
| 372 | + $schema['paths'], |
| 373 | + $fixes['paths'] |
| 374 | + ); |
| 375 | + } |
| 376 | + |
| 377 | + return $schema; |
| 378 | +} |
| 379 | + |
348 | 380 | /** |
349 | 381 | * Prepares schemas for api/model generation using janephp. |
350 | 382 | */ |
351 | 383 | function customizeSchemas(array $categories, array $countries, array $apiCodes): void |
352 | 384 | { |
353 | 385 | $schemas = schemas($categories, $countries, $apiCodes); |
354 | 386 | foreach ($schemas as $schemaInfo) { |
355 | | - customizeSchema($schemaInfo['path'], $schemaInfo['category'], $schemaInfo['api']['name']); |
| 387 | + customizeSchema( |
| 388 | + $schemaInfo['path'], |
| 389 | + $schemaInfo['category'], |
| 390 | + $schemaInfo['country'], |
| 391 | + $schemaInfo['api']['code'], |
| 392 | + $schemaInfo['api']['name'], |
| 393 | + ); |
356 | 394 | } |
357 | 395 | } |
358 | 396 |
|
|
0 commit comments