- Phase 1-3: 핵심/보조 문서 업데이트, 버전 최신화 - Phase 4: 오래된 파일 정리 및 아카이브 - D0.8 Storyboard → history/2025-12/ 이동 - admin 참조 4개 파일 수정 (docker-setup, git-conventions, project-launch-roadmap, remote-work-setup) - 빈 디렉토리 6개 삭제 - 버전 정보: React 19.2.1, Next.js 15.5.7 - remote-work-setup.md DEPRECATED 표시
245 lines
5.7 KiB
Markdown
245 lines
5.7 KiB
Markdown
# Swagger 문서화 가이드
|
|
|
|
**업데이트**: 2025-12-26
|
|
|
|
---
|
|
|
|
## 개요
|
|
|
|
**라이브러리**: l5-swagger 9.0
|
|
|
|
## Swagger 구조
|
|
|
|
### 파일 위치
|
|
- **경로**: `app/Swagger/v1/`
|
|
- **파일명**: `{Resource}Api.php` (예: CategoryApi.php, ClientApi.php, ProductApi.php)
|
|
|
|
### 원칙
|
|
- **Controller Clean**: Controllers contain ONLY business logic, NO Swagger annotations
|
|
- **Separate Files**: Swagger annotations are written in separate PHP class files
|
|
|
|
---
|
|
|
|
## Swagger 파일 구조
|
|
|
|
### 기본 템플릿
|
|
|
|
```php
|
|
<?php
|
|
namespace App\Swagger\v1;
|
|
|
|
/**
|
|
* @OA\Tag(name="Resource", description="리소스 관리")
|
|
*
|
|
* @OA\Schema(
|
|
* schema="Resource",
|
|
* @OA\Property(property="id", type="integer"),
|
|
* @OA\Property(property="name", type="string"),
|
|
* ...
|
|
* )
|
|
*
|
|
* @OA\Schema(
|
|
* schema="ResourcePagination",
|
|
* allOf={
|
|
* @OA\Schema(ref="#/components/schemas/PaginationMeta"),
|
|
* @OA\Schema(
|
|
* @OA\Property(
|
|
* property="data",
|
|
* type="array",
|
|
* @OA\Items(ref="#/components/schemas/Resource")
|
|
* )
|
|
* )
|
|
* }
|
|
* )
|
|
*
|
|
* @OA\Schema(
|
|
* schema="ResourceCreateRequest",
|
|
* required={"name"},
|
|
* @OA\Property(property="name", type="string"),
|
|
* ...
|
|
* )
|
|
*
|
|
* @OA\Schema(
|
|
* schema="ResourceUpdateRequest",
|
|
* @OA\Property(property="name", type="string"),
|
|
* ...
|
|
* )
|
|
*/
|
|
class ResourceApi
|
|
{
|
|
/**
|
|
* @OA\Get(
|
|
* path="/api/v1/resources",
|
|
* tags={"Resource"},
|
|
* summary="리소스 목록 조회",
|
|
* security={{"ApiKeyAuth": {}, "BearerAuth": {}}},
|
|
* @OA\Parameter(
|
|
* name="page",
|
|
* in="query",
|
|
* @OA\Schema(type="integer", default=1)
|
|
* ),
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="성공",
|
|
* @OA\JsonContent(ref="#/components/schemas/ResourcePagination")
|
|
* )
|
|
* )
|
|
*/
|
|
public function index() {}
|
|
|
|
/**
|
|
* @OA\Post(
|
|
* path="/api/v1/resources",
|
|
* tags={"Resource"},
|
|
* summary="리소스 생성",
|
|
* security={{"ApiKeyAuth": {}, "BearerAuth": {}}},
|
|
* @OA\RequestBody(
|
|
* required=true,
|
|
* @OA\JsonContent(ref="#/components/schemas/ResourceCreateRequest")
|
|
* ),
|
|
* @OA\Response(
|
|
* response=201,
|
|
* description="생성 성공",
|
|
* @OA\JsonContent(ref="#/components/schemas/Resource")
|
|
* )
|
|
* )
|
|
*/
|
|
public function store() {}
|
|
|
|
/**
|
|
* @OA\Get(
|
|
* path="/api/v1/resources/{id}",
|
|
* tags={"Resource"},
|
|
* summary="리소스 상세 조회",
|
|
* security={{"ApiKeyAuth": {}, "BearerAuth": {}}},
|
|
* @OA\Parameter(
|
|
* name="id",
|
|
* in="path",
|
|
* required=true,
|
|
* @OA\Schema(type="integer")
|
|
* ),
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="성공",
|
|
* @OA\JsonContent(ref="#/components/schemas/Resource")
|
|
* )
|
|
* )
|
|
*/
|
|
public function show() {}
|
|
|
|
/**
|
|
* @OA\Put(
|
|
* path="/api/v1/resources/{id}",
|
|
* tags={"Resource"},
|
|
* summary="리소스 수정",
|
|
* security={{"ApiKeyAuth": {}, "BearerAuth": {}}},
|
|
* @OA\Parameter(
|
|
* name="id",
|
|
* in="path",
|
|
* required=true,
|
|
* @OA\Schema(type="integer")
|
|
* ),
|
|
* @OA\RequestBody(
|
|
* required=true,
|
|
* @OA\JsonContent(ref="#/components/schemas/ResourceUpdateRequest")
|
|
* ),
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="수정 성공",
|
|
* @OA\JsonContent(ref="#/components/schemas/Resource")
|
|
* )
|
|
* )
|
|
*/
|
|
public function update() {}
|
|
|
|
/**
|
|
* @OA\Delete(
|
|
* path="/api/v1/resources/{id}",
|
|
* tags={"Resource"},
|
|
* summary="리소스 삭제",
|
|
* security={{"ApiKeyAuth": {}, "BearerAuth": {}}},
|
|
* @OA\Parameter(
|
|
* name="id",
|
|
* in="path",
|
|
* required=true,
|
|
* @OA\Schema(type="integer")
|
|
* ),
|
|
* @OA\Response(
|
|
* response=200,
|
|
* description="삭제 성공"
|
|
* )
|
|
* )
|
|
*/
|
|
public function destroy() {}
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## 필수 규칙
|
|
|
|
### 1. Tags
|
|
- Resource-based (User, Auth, Product, BOM, Client...)
|
|
- 리소스별 논리적 그룹핑
|
|
|
|
### 2. Security
|
|
```php
|
|
security={{"ApiKeyAuth": {}, "BearerAuth": {}}}
|
|
```
|
|
- 모든 엔드포인트에 필수
|
|
|
|
### 3. Schemas
|
|
- **Resource model**: 응답 데이터 구조
|
|
- **Pagination**: 페이지네이션 응답 (PaginationMeta 재사용)
|
|
- **CreateRequest**: 생성 요청 스키마
|
|
- **UpdateRequest**: 수정 요청 스키마
|
|
|
|
### 4. Parameters
|
|
- Path/Query/Body parameters 명확히 정의
|
|
- 예시 값 제공 (example 속성)
|
|
|
|
### 5. 중복 방지
|
|
- **No duplicate schemas**: 공통 스키마는 재사용
|
|
- nullable/oneOf 정확한 구분
|
|
|
|
---
|
|
|
|
## Swagger 재생성
|
|
|
|
```bash
|
|
php artisan l5-swagger:generate
|
|
```
|
|
|
|
**실행 시점:**
|
|
- Swagger 파일 생성/수정 후
|
|
- API 엔드포인트 변경 후
|
|
|
|
---
|
|
|
|
## 접근 방법
|
|
|
|
- **Swagger UI**: http://api.sam.kr/api-docs/index.html
|
|
- **JSON Spec**: http://api.sam.kr/docs/api-docs.json
|
|
|
|
---
|
|
|
|
## 체크리스트
|
|
|
|
```
|
|
✓ Swagger 파일 위치: app/Swagger/v1/{Resource}Api.php
|
|
✓ Controller에 Swagger 주석 없음
|
|
✓ Resource 태그 적용
|
|
✓ ApiKeyAuth + BearerAuth 스키마
|
|
✓ 스키마 재사용 (중복 없음)
|
|
✓ 예시 값 제공
|
|
✓ php artisan l5-swagger:generate 실행
|
|
```
|
|
|
|
## 관련 문서
|
|
|
|
- [API 개발 규칙](./api_rules.md)
|
|
- [개발 명령어](./dev_commands.md)
|
|
|
|
---
|
|
|
|
**최종 업데이트**: 2025-12-26 |