From 4351571fdda0eedb88bc8e1428fe35921293fa8e Mon Sep 17 00:00:00 2001 From: Aprilia Agung Nugroho Date: Mon, 17 Jul 2023 16:02:44 +0700 Subject: [PATCH] solve issue https://github.com/ovac/idoc/issues/39 --- src/idoc/IDocGeneratorCommand.php | 34 +++++++++++++++---------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/idoc/IDocGeneratorCommand.php b/src/idoc/IDocGeneratorCommand.php index 9ab2b81..1eac5e2 100644 --- a/src/idoc/IDocGeneratorCommand.php +++ b/src/idoc/IDocGeneratorCommand.php @@ -324,23 +324,21 @@ function ($parameter) { ->toArray() ), - 'responses' => [ - 200 => [ - 'description' => 'success', - ] + - ( - count($route['response'] ?? []) - ? ['content' => [ - 'application/json' => [ - 'schema' => [ - 'type' => 'object', - 'example' => json_decode($route['response'][0]['content'], true), - ], - ], - ]] - : [] - ), - ], + 'responses' => collect($route['response'])->mapWithKeys(function($item) { + return [ + (int) $item['status'] => [ + 'description' => in_array($item['status'], range(200,299)) ? 'success' : 'error', + 'content' => [ + 'application/json' => [ + 'schema' => [ + 'type' => 'object', + 'example' => json_decode($item['content']) + ] + ] + ] + ] + ]; + })->all(), 'x-code-samples' => collect(config('idoc.language-tabs'))->map(function ($name, $lang) use ($route) { return [ @@ -377,7 +375,7 @@ function ($parameter) { 'description' => config('idoc.description'), 'termsOfService' => config('idoc.terms_of_service'), "license" => !empty(config('idoc.license')) ? config('idoc.license') : null, - "contact" => config('idoc.contact'), + "contact" => config('idoc.contact'), "x-logo" => [ "url" => config('idoc.logo'), "altText" => config('idoc.title'),