-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathswaggerSort.php
More file actions
25 lines (19 loc) · 812 Bytes
/
swaggerSort.php
File metadata and controls
25 lines (19 loc) · 812 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<?php
unset($argv[0]);
$keysToSort = ['type', 'logType', 'size', 'status'];
foreach($argv as $file) {
$contentFile = json_decode(file_get_contents($file), true);
foreach ($contentFile['definitions'] as $key => &$content) {
foreach ($keysToSort as $keyToSort) {
if (isset($content['properties'][$keyToSort]) && isset($content['properties'][$keyToSort]['enum'])) {
sort($content['properties'][$keyToSort]['enum']);
}
}
}
foreach ($contentFile['paths'] as $route => &$method) {
if (isset($method['get']['responses']['200']['schema']['items']['enum'])) {
sort($method['get']['responses']['200']['schema']['items']['enum']);
}
}
file_put_contents($file, json_encode($contentFile, JSON_PRETTY_PRINT));
}