Skip to content

Commit

Permalink
fix(scopes): Improve help when not reading schemas
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <[email protected]>
  • Loading branch information
nickvergessen committed Jan 12, 2024
1 parent 9abc4c1 commit 810ef64
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions generate-spec
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
}
Expand Down

0 comments on commit 810ef64

Please sign in to comment.