1818 * @Target("METHOD")
1919 * @Attributes({
2020 * @Attribute("status",type="integer"),
21+ * @Attribute("isSuccessful",type="boolean"),
2122 * @Attribute("contentType",type="string"),
2223 * @Attribute("description",type="string"),
2324 * @Attribute("asList",type="boolean"),
@@ -30,6 +31,7 @@ class Response extends BaseAnnotation
3031 public mixed $ content = null ;
3132 public string $ contentType = 'application/json ' ;
3233 public int $ status = 200 ;
34+ public ?bool $ isSuccessful = null ;
3335 public ?string $ description = null ;
3436 public bool $ asList = false ;
3537 public bool $ asPagedList = false ;
@@ -179,12 +181,12 @@ public function __toString()
179181 protected function wrapInDefaultResponse (mixed $ content = null ): mixed
180182 {
181183 $ content = $ content ?? $ this ->content ;
182- $ responseData = static ::getDefaultResponse ($ this ->contentType , $ this ->status );
184+ $ responseData = static ::getDefaultResponse ($ this ->contentType , $ this ->status , $ this -> isSuccessful );
183185 if ($ responseData === null ) {
184186 return $ content ;
185187 }
186188 [$ responseRaw , $ resultKey ] = array_values ($ responseData );
187- if (($ this ->asPagedList || $ this ->asCursorPagedList ) && static ::isSuccessStatus ($ this ->status )) {
189+ if (($ this ->asPagedList || $ this ->asCursorPagedList ) && ( $ this -> isSuccessful ?? static ::isSuccessStatus ($ this ->status ) )) {
188190 if ($ this ->asPagedList ) {
189191 $ responseRaw ['pagination ' ] = static ::getPagerExample ();
190192 } elseif ($ this ->asCursorPagedList ) {
@@ -200,13 +202,14 @@ protected function wrapInDefaultResponse(mixed $content = null): mixed
200202 /**
201203 * Get default response by content type [response, result_array_key].
202204 *
203- * @param string $contentType
204- * @param int $status
205+ * @param string $contentType
206+ * @param int $status
207+ * @param bool|null $isSuccessful Override check by status for success/error response
205208 * @return mixed|null
206209 */
207- protected static function getDefaultResponse (string $ contentType , int $ status = 200 ): mixed
210+ protected static function getDefaultResponse (string $ contentType , int $ status = 200 , ? bool $ isSuccessful = null ): mixed
208211 {
209- $ key = static ::isSuccessStatus ($ status ) ? 'ok ' : 'error ' ;
212+ $ key = ( $ isSuccessful ?? static ::isSuccessStatus ($ status) ) ? 'ok ' : 'error ' ;
210213 $ responses = [
211214 'application/json ' => [
212215 'ok ' => [
0 commit comments