From 810ef64bc42a43e9678ab0800ba1c113ceb9c791 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 12 Jan 2024 14:43:44 +0100 Subject: [PATCH] fix(scopes): Improve help when not reading schemas Signed-off-by: Joas Schilling --- generate-spec | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/generate-spec b/generate-spec index d1631c4..83acbd6 100755 --- a/generate-spec +++ b/generate-spec @@ -804,17 +804,28 @@ foreach ($scopePaths as $scope => $paths) { foreach ($paths as $url => $urlRoutes) { foreach ($urlRoutes as $httpMethod => $routeData) { foreach ($routeData['responses'] as $statusCode => $responseData) { - if (isset($responseData['content']['application/json'])) { - if (is_array($responseData['content']['application/json']['schema'])) { - $newSchemas = Helpers::collectUsedRefs($responseData['content']['application/json']['schema']); - $usedSchemas = array_merge($usedSchemas, $newSchemas); + if (empty($responseData['content'])) { + continue; + } + + foreach ($responseData['content'] as $contentType => $contentData) { + if ($contentType === 'application/json') { + if (isset($contentData['schema']) && is_array($contentData['schema'])) { + $newSchemas = Helpers::collectUsedRefs($contentData['schema']); + $usedSchemas = array_merge($usedSchemas, $newSchemas); + } + } elseif ( + ( + in_array($contentType, ['*/*', 'text/css', 'application/octet-stream'], true) + || str_starts_with($contentType, 'image/') + ) + && isset($contentData['schema']['type'], $contentData['schema']['format']) + && $contentData['schema']['type'] === 'string' + && $contentData['schema']['format'] === 'binary') { + Logger::debug("app", "Binary response from '$httpMethod $url' - Skipping schema reading"); + } elseif (isset($contentData['schema'])) { + Logger::warning("app", "Could not read used schemas for response to '$httpMethod $url' with status code $statusCode with content type $contentType"); } - } elseif (isset($responseData['content']['*/*']['schema']['type'], $responseData['content']['*/*']['schema']['format']) - && $responseData['content']['*/*']['schema']['type'] === 'string' - && $responseData['content']['*/*']['schema']['format'] === 'binary') { - Logger::debug("app", "Binary response from '$httpMethod $url' - Skipping schema reading"); - } else { - Logger::warning("app", "Could not read used schemas for response to '$httpMethod $url' with status code $statusCode"); } } }