feat: [API Explorer] Phase 1 완성 - 히스토리 로드, 밸리데이션, 유니코드 처리

- 히스토리 로드 기능 구현 (loadFromHistory, fillFormFromHistory)
- 클라이언트 사이드 필수값 밸리데이션 추가
- 응답 본문 \xXX UTF-8 바이트 시퀀스 디코딩 (PHP 스택트레이스 한글 깨짐 해결)
- sidebar에 data-operation-id 속성 추가
- history-drawer 함수 연결 수정
- Flow Tester 변수 바인딩 개선
- 마이그레이션 파일 통합 정리
This commit is contained in:
2025-12-18 15:42:01 +09:00
parent 2ed273097e
commit a62337ef5c
15 changed files with 1328 additions and 217 deletions

View File

@@ -43,12 +43,16 @@ public function index(): View
$environments = $this->explorer->getEnvironments($userId);
$defaultEnv = $this->explorer->getDefaultEnvironment($userId);
// 세션에 저장된 토큰
$savedToken = session('api_explorer_token');
return view('dev-tools.api-explorer.index', compact(
'endpoints',
'tags',
'bookmarks',
'environments',
'defaultEnv'
'defaultEnv',
'savedToken'
));
}
@@ -119,13 +123,42 @@ public function execute(Request $request): JsonResponse
'query' => 'nullable|array',
'body' => 'nullable|array',
'environment' => 'required|string',
'token' => 'nullable|string',
'user_id' => 'nullable|integer',
]);
// Bearer 토큰 처리
$token = null;
$headers = $validated['headers'] ?? [];
// 1. 직접 입력된 토큰
if (! empty($validated['token'])) {
$token = $validated['token'];
session(['api_explorer_token' => $token]);
}
// 2. 사용자 선택 시 Sanctum 토큰 발급
elseif (! empty($validated['user_id'])) {
$user = \App\Models\User::find($validated['user_id']);
if ($user) {
$token = $user->createToken('api-explorer', ['*'])->plainTextToken;
session(['api_explorer_token' => $token]);
}
}
// 3. 세션에 저장된 토큰 재사용
elseif (session('api_explorer_token')) {
$token = session('api_explorer_token');
}
// Authorization 헤더 추가 (사용자 입력 토큰이 우선)
if ($token) {
$headers['Authorization'] = 'Bearer ' . $token;
}
// API 실행
$result = $this->requester->execute(
$validated['method'],
$validated['url'],
$validated['headers'] ?? [],
$headers,
$validated['query'] ?? [],
$validated['body']
);
@@ -384,4 +417,26 @@ public function setDefaultEnvironment(int $id): JsonResponse
return response()->json(['success' => true]);
}
/*
|--------------------------------------------------------------------------
| Users (for Authentication)
|--------------------------------------------------------------------------
*/
/**
* 현재 테넌트의 사용자 목록
*/
public function users(): JsonResponse
{
$tenantId = auth()->user()->tenant_id;
$users = \App\Models\User::where('tenant_id', $tenantId)
->select(['id', 'name', 'email'])
->orderBy('name')
->limit(100)
->get();
return response()->json($users);
}
}