-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathopenapi.php
More file actions
25 lines (22 loc) · 1007 Bytes
/
openapi.php
File metadata and controls
25 lines (22 loc) · 1007 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
function sortOpenApiContent(array &$openApi): void
{
foreach ($openApi['paths'] as $path => &$pathMethods) {
foreach ($pathMethods as $method => &$methodDefinition) {
if (array_key_exists('requestBody', $methodDefinition) && array_key_exists('content', $methodDefinition['requestBody'])) {
ksort($methodDefinition['requestBody']['content']);
}
foreach ($methodDefinition['responses'] as $responseCode => &$responseDefinition) {
if (array_key_exists('content', $responseDefinition)) {
ksort($responseDefinition['content']);
}
}
}
}
}
$openApi = yaml_parse_file('openapi.yaml');
sortOpenApiContent($openApi);
yaml_emit_file('openapi.yaml', $openApi);
$openApiJson = json_decode(file_get_contents('openapi.json'), true);
sortOpenApiContent($openApiJson);
file_put_contents('openapi.json', json_encode($openApiJson, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));