我有一个使用Laravel作为api和swagger作为文档的项目。
在我的登录控制器中有这样的方法:
/**
 * Handle an incoming authentication request.
 * 
 * 
 * @OA\Post(
 *     tags={"UnAuthorize"},
 *     path="/login",
 *     summary="User Login",
 *     @OA\RequestBody(
 *          @OA\MediaType(
 *              mediaType="application/json",
 *              @OA\Schema(
 *                  type="object",    
 *                  ref="#/components/schemas/LoginRequest",                  
 *              )
 *          )
 *     ),
 *     @OA\Response(
 *          response="200", 
 *          description="An example resource", 
 *          @OA\JsonContent(
 *              type="object", 
 *              @OA\Property(
 *                  format="string", 
 *                  default="20d338931e8d6bd9466edeba78ea7dce7c7bc01aa5cc5b4735691c50a2fe3228", 
 *                  description="token", 
 *                  property="token"
 *              )
 *          ),
 *         @OA\JsonContent(ref="#/components/schemas/UserResource")
 *     ),
 *     @OA\Response(response="401", description="fail"),
 * )
 *
 * @param  \App\Http\Requests\Auth\LoginRequest  $request
 * @return \Illuminate\Http\JsonResponse
 */
public function store(LoginRequest $request)
{                
    $request->authenticate();                
  
    return response()->json(
        [ 
           "token" => $request->user()->createToken($request->email)->plainTextToken,
           "user" => $request->user();  
        ]
    );
        
    
}然后,当我运行以下命令: php l5-swagger:generate时,它将显示以下错误:
c:\myproject\vendor\zircote\swagger-php\src\Logger.php:40 36▕$this->log =函数( $entry,$type) { 37▕if ($entry instanceof Exception) { 38▕$entry= $entry->getMessage();39▕}➜40▕trigger_error($entry,$type);41▕};42▕}
当我移除这个
@OA\JsonContent(ref="#/components/schemas/UserResource")它可以工作,但是没有显示用户数据,也许我应该只返回令牌,然后使用令牌发出另一个请求,以获取有关日志用户的信息。我能做什么?谢谢
编辑:
@OA\Response(
     *          response="200", 
     *          description="An example resource", 
     *          @OA\JsonContent(
     *              type="object", 
     *              @OA\Property(
     *                  format="string", 
     *                  default="20d338931e8d6bd9466edeba78ea7dce7c7bc01aa5cc5b4735691c50a2fe3228", 
     *                  description="token", 
     *                  property="token"
     *              ),
     *              @OA\Property(
     *                  format="application/json", 
     *                  property="user",
     *                  @OA\JsonContent(ref="#/components/schemas/UserResource") 
     *              )
     *          ),     
     *     )我试过了,但它显示出错误
发布于 2022-04-26 21:21:26
非常接近除了..。
使用“格式”代替“类型”( @OA\JsonContent
这里是我的观点,它是独立工作的(除了缺少的@OA\Info):
<?php
use OpenApi\Annotations\OpenApi as OA;
/**
 * @OA\Schema
 */
class LoginRequest{}
/**
 * @OA\Schema
 */
class UserResource{}
/**
 * Handle an incoming authentication request.
 *
 *
 * @OA\Post(
 *     tags={"UnAuthorize"},
 *     path="/login",
 *     summary="User Login",
 *     @OA\RequestBody(
 *          @OA\MediaType(
 *              mediaType="application/json",
 *              @OA\Schema(
 *                  type="object",
 *                  ref="#/components/schemas/LoginRequest"
 *              )
 *          )
 *     ),
 *     @OA\Response(
 *          response="200",
 *          description="An example resource",
 *          @OA\JsonContent(
 *              type="object",
 *              @OA\Property(
 *                  type="string",
 *                  default="20d338931e8d6bd9466edeba78ea7dce7c7bc01aa5cc5b4735691c50a2fe3228",
 *                  description="token",
 *                  property="token"
 *              ),
 *              @OA\Property(
 *                  property="user",
 *                  ref="#/components/schemas/UserResource"
 *              )
 *          )
 *     ),
 *     @OA\Response(response="401", description="fail")
 * )
 *
 */
class Controller {}发布于 2022-04-26 16:26:33
您删除的JsonContent应该是我认为的第一个JsonContent上的属性
https://stackoverflow.com/questions/72016886
复制相似问题