@@ -103,8 +103,12 @@ function loadSpec(string $path): array {
103103 return rewriteRefs (json_decode (file_get_contents ($ path ), true ));
104104}
105105
106+ function getAppID (array $ spec ): string {
107+ return explode ('- ' , $ spec ['info ' ]['title ' ])[0 ];
108+ }
109+
106110function rewriteRefs (array $ spec ): array {
107- $ readableAppID = Helpers::generateReadableAppID ($ spec[ ' info ' ][ ' title ' ] );
111+ $ readableAppID = Helpers::generateReadableAppID (getAppID ( $ spec) );
108112 array_walk_recursive ($ spec , function (mixed &$ item , string $ key ) use ($ readableAppID ): void {
109113 if ($ key === '$ref ' && $ item !== '#/components/schemas/OCSMeta ' ) {
110114 $ item = str_replace ('#/components/schemas/ ' , '#/components/schemas/ ' . $ readableAppID , $ item );
@@ -115,7 +119,7 @@ function rewriteRefs(array $spec): array {
115119
116120function collectCapabilities (array $ spec ): array {
117121 $ capabilities = [];
118- $ readableAppID = Helpers::generateReadableAppID ($ spec[ ' info ' ][ ' title ' ] );
122+ $ readableAppID = Helpers::generateReadableAppID (getAppID ( $ spec) );
119123 foreach (array_keys ($ spec ['components ' ]['schemas ' ]) as $ name ) {
120124 if ($ name == 'Capabilities ' || $ name == 'PublicCapabilities ' ) {
121125 $ capabilities [] = $ readableAppID . $ name ;
@@ -127,7 +131,7 @@ function collectCapabilities(array $spec): array {
127131
128132function rewriteSchemaNames (array $ spec ): array {
129133 $ schemas = $ spec ['components ' ]['schemas ' ];
130- $ readableAppID = Helpers::generateReadableAppID ($ spec[ ' info ' ][ ' title ' ] );
134+ $ readableAppID = Helpers::generateReadableAppID (getAppID ( $ spec) );
131135 return array_combine (
132136 array_map (fn (string $ key ): string => $ key === 'OCSMeta ' ? $ key : $ readableAppID . $ key , array_keys ($ schemas )),
133137 array_values ($ schemas ),
@@ -136,7 +140,7 @@ function rewriteSchemaNames(array $spec): array {
136140
137141function rewriteTags (array $ spec ): array {
138142 return array_map (function (array $ tag ) use ($ spec ) {
139- $ tag ['name ' ] = $ spec[ ' info ' ][ ' title ' ] . '/ ' . $ tag ['name ' ];
143+ $ tag ['name ' ] = getAppID ( $ spec) . '/ ' . $ tag ['name ' ];
140144 return $ tag ;
141145 }, $ spec ['tags ' ]);
142146}
@@ -151,12 +155,12 @@ function rewriteOperations(array $spec): array {
151155 }
152156 $ operation = &$ spec ['paths ' ][$ path ][$ method ];
153157 if (array_key_exists ('operationId ' , $ operation )) {
154- $ operation ['operationId ' ] = $ spec[ ' info ' ][ ' title ' ] . '- ' . $ operation ['operationId ' ];
158+ $ operation ['operationId ' ] = getAppID ( $ spec) . '- ' . $ operation ['operationId ' ];
155159 }
156160 if (array_key_exists ('tags ' , $ operation )) {
157- $ operation ['tags ' ] = array_map (fn (string $ tag ): string => $ spec[ ' info ' ][ ' title ' ] . '/ ' . $ tag , $ operation ['tags ' ]);
161+ $ operation ['tags ' ] = array_map (fn (string $ tag ): string => getAppID ( $ spec) . '/ ' . $ tag , $ operation ['tags ' ]);
158162 } else {
159- $ operation ['tags ' ] = [$ spec[ ' info ' ][ ' title ' ] ];
163+ $ operation ['tags ' ] = [getAppID ( $ spec) ];
160164 }
161165 if ($ firstStatusCode && array_key_exists ('responses ' , $ operation )) {
162166 /** @var string $value */
0 commit comments