scramble icon indicating copy to clipboard operation
scramble copied to clipboard

Union type annotation results in missing response docs

Open romalytvynenko opened this issue 1 year ago • 0 comments

          Were having the same issue described, but even without the array aspect... essentially anything with a multiple type response adds the first response, and ignores the rest.

This...

/**
 * Verify a user using their email address.
 * @unauthenticated
 *
 * @param Request $request
 * @param string $verificationId
 *
 * @return UserVerificationResource|JsonResponse
 */
public function email(Request $request, string $verificationId): UserVerificationResource|JsonResponse
{
    $userVerification = UserVerification::with(['user'])
                                        ->where('type', 'email')
                                        ->where('id', $verificationId)
                                        ->first();

    if (
        !$userVerification ||
        $userVerification->expires->isPast() ||
        $userVerification->attempts >= $this->authSettings->max_verify_attempts
    ) {
        return response()->json(
            [
                'meta' => [
                    'status' => '410',
                    'message' => 'Invalid User Verification code',
                ],
            ],
            410
        );
    }

    return new UserVerificationResource($userVerification);
}

Sadly results in only the UserVerificationResource showing in the docs or export, however if you swap the declarations for the return or typecast, then you get the JsonResponse listed, and no UserVerificationResource.

What is strange, is that if I remove the DocBlock AND the return Typehint, then the output is exactly as expected.

Originally posted by @J5Dev in https://github.com/dedoc/scramble/issues/601#issuecomment-2520447055

romalytvynenko avatar Dec 06 '24 06:12 romalytvynenko