From 6a41c89d1fd08fa144955a22ecfddbd2ed9fc64b Mon Sep 17 00:00:00 2001 From: Wouter Bohlken Date: Mon, 11 Dec 2023 15:59:28 +0100 Subject: [PATCH] Make default responses configurable --- config/swagger-generator.php | 19 +++++++++++++++++++ oa/Response.php | 22 ++++------------------ 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/config/swagger-generator.php b/config/swagger-generator.php index 9c40b23..2fb2541 100644 --- a/config/swagger-generator.php +++ b/config/swagger-generator.php @@ -90,4 +90,23 @@ | */ 'generateDefinitions' => [], + + 'defaultResponses' => [ + 'ok' => [ + 'response' => [ + 'success' => true, + 'message' => 'OK', + 'result' => false, + ], + 'resultKey' => 'properties.result', + ], + 'error' => [ + 'response' => [ + 'success' => false, + 'message' => 'Error', + 'errors' => [], + ], + 'resultKey' => 'properties.errors', + ], + ], ]; diff --git a/oa/Response.php b/oa/Response.php index 50b46ed..8a2d193 100644 --- a/oa/Response.php +++ b/oa/Response.php @@ -207,25 +207,11 @@ protected function wrapInDefaultResponse(mixed $content = null): mixed protected static function getDefaultResponse(string $contentType, int $status = 200): mixed { $key = static::isSuccessStatus($status) ? 'ok' : 'error'; + + $defaultResponses = config('swagger-generator.defaultResponses'); + $responses = [ - 'application/json' => [ - 'ok' => [ - 'response' => [ - 'success' => true, - 'message' => 'OK', - 'result' => false, - ], - 'resultKey' => 'properties.result', - ], - 'error' => [ - 'response' => [ - 'success' => false, - 'message' => 'Error', - 'errors' => [], - ], - 'resultKey' => 'properties.errors', - ], - ], + 'application/json' => $defaultResponses, ]; $responseKey = $contentType . '.' . $key;