# API Skill CLI

[English](https://unpkg.com/apiskill@latest/docs/cli.md) / [中文](https://unpkg.com/apiskill@latest/docs/cli.zh.md) / [한국어](https://unpkg.com/apiskill@latest/docs/cli.ko.md) / [日本語](https://unpkg.com/apiskill@latest/docs/cli.ja.md)

## 설치 및 실행

프로젝트 루트에서 실행합니다.

```bash
npm install
npm run cli -- --help
```

실행 파일을 직접 실행할 수도 있습니다.

```bash
node scripts/apiskill-cli.mjs --help
```

## 문서 가져오기

사용 가능한 캐시가 있는지 먼저 확인합니다.

```bash
npm run cli -- check
npm run cli -- check --json
```

사용 가능한 캐시가 없으면 `check`가 가져오기 예시를 출력합니다.

```bash
npm run cli -- import https://example.com/openapi.json
npm run cli -- crawl https://example.com/swagger
npm run cli -- import-file ./openapi.yaml
npm run cli -- import-curl --file ./request.curl
```

문서 엔드포인트에 basic auth가 필요하면 `import` 또는 `crawl`에 `--auth username:password`를 추가합니다.

## 처음부터 문서 만들기

아직 상위 OpenAPI 문서가 없다면 빈 로컬 문서 버전을 먼저 생성합니다.

```bash
npm run cli -- document create --title "My API" --doc-version 1.0.0
npm run cli -- document create --title "My API" --doc-version 1.0.0 --description "Internal service contract" --json
```

생성된 문서는 최신 캐시 버전으로 저장됩니다. 이후 `api create --version <versionId>`로 엔드포인트를 추가하거나, 빈 문서가 이미 최신 버전이면 `--version`을 생략할 수 있습니다.

## 버전과 API 조회

```bash
npm run cli -- versions
npm run cli -- versions --json
npm run cli -- query /admin/api/v1/user/list --method GET
npm run cli -- query user --method POST --limit 10
npm run cli -- api list --query user --method post
npm run cli -- api query GET /api/v1/user --format cli
```

`query`는 MCP의 `apiskill_query_api` 도구와 같은 방식으로 동작합니다. 정확한 단일 매치가 있으면 하나의 API 설정을 반환하고, 여러 개가 매치되면 후보 목록을 반환합니다.

## 수동 API 생성, 편집, 삭제

```bash
npm run cli -- api create --file ./api-config.yaml
npm run cli -- api edit GET /api/v1/user --file ./api-config.json --version 20260429T000000Z-manual-user
npm run cli -- api delete GET /api/v1/user --version 20260429T000000Z-manual-user
```

CLI 설정은 JSON 또는 YAML을 사용할 수 있으며 루트 키로 `api`, `config`, `operation`을 지원합니다.

최소 JSON 예시:

```json
{
  "api": {
    "method": "post",
    "path": "/api/v1/example",
    "summary": "예시 생성",
    "responses": [
      {
        "status": "200",
        "description": "Success"
      }
    ]
  }
}
```
