| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- # ============================================================================
- # ANTOOZA Postman Collection 갱신 스크립트
- #
- # 사용법:
- # 1. 백엔드 실행 (다른 터미널)
- # cd E:\workspace\antooza\Backend
- # dotnet run --project Web.Api
- #
- # 2. 이 스크립트 실행
- # cd E:\workspace\antooza\Backend\Web.Api\postman
- # pwsh ./update.ps1
- #
- # 옵션:
- # -ApiBase <url> 기본값: https://localhost:4000
- # -SkipInternal internal swagger 변환 생략
- #
- # 결과:
- # collections/ANTOOZA-Internal-API.postman_collection.json (내부 /api/*)
- #
- # 요구사항:
- # - Node.js (npx 포함) — openapi-to-postmanv2 를 npx 로 1회성 실행
- # - 실행 중인 로컬 백엔드 (internal swagger 는 Production 에 차단되어 로컬 필수)
- # ============================================================================
- [CmdletBinding()]
- param(
- [string]$ApiBase = "https://localhost:4000",
- [switch]$SkipInternal
- )
- $ErrorActionPreference = "Stop"
- $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
- Set-Location $scriptDir
- function Write-Step($msg) { Write-Host "[$(Get-Date -Format 'HH:mm:ss')] $msg" -ForegroundColor Cyan }
- function Write-Ok($msg) { Write-Host " [OK] $msg" -ForegroundColor Green }
- function Write-Fail($msg) { Write-Host " [!!] $msg" -ForegroundColor Red }
- # 1) 백엔드 health check
- Write-Step "백엔드 health check ($ApiBase/health)"
- try {
- $r = Invoke-WebRequest -Uri "$ApiBase/health" -SkipCertificateCheck -TimeoutSec 5 -UseBasicParsing
- if ($r.StatusCode -ne 200) {
- Write-Fail "health 응답 $($r.StatusCode) — 백엔드 실행 상태 확인 필요"
- exit 1
- }
- Write-Ok "백엔드 정상 응답"
- } catch {
- Write-Fail "백엔드 접근 실패: $($_.Exception.Message)"
- Write-Host " 먼저 다른 터미널에서 다음 명령을 실행하세요:" -ForegroundColor Yellow
- Write-Host " cd E:\workspace\antooza\Backend; dotnet run --project Web.Api" -ForegroundColor Yellow
- exit 1
- }
- # 2) Node/npx 사용 가능 확인
- Write-Step "Node.js / npx 확인"
- $nodeVer = (& node -v) 2>$null
- $npxVer = (& npx --version) 2>$null
- if (-not $nodeVer -or -not $npxVer) {
- Write-Fail "Node.js 또는 npx 가 없습니다. https://nodejs.org 에서 설치하세요."
- exit 1
- }
- Write-Ok "node $nodeVer / npx $npxVer"
- # 3) collections 폴더 보장
- $colDir = Join-Path $scriptDir "collections"
- if (-not (Test-Path $colDir)) {
- New-Item -ItemType Directory -Path $colDir | Out-Null
- }
- function Convert-Swagger {
- param(
- [string]$DocName, # internal
- [string]$OutName # ANTOOZA-Internal-API
- )
- Write-Step "$DocName swagger 변환"
- $swaggerUrl = "$ApiBase/swagger/$DocName/swagger.json"
- $tmpFile = Join-Path $env:TEMP "antooza-$DocName.json"
- $outFile = Join-Path $colDir "$OutName.postman_collection.json"
- # fetch
- try {
- Invoke-WebRequest -Uri $swaggerUrl -SkipCertificateCheck -OutFile $tmpFile -UseBasicParsing | Out-Null
- $size = (Get-Item $tmpFile).Length
- Write-Ok "$swaggerUrl => $size bytes"
- } catch {
- Write-Fail "swagger fetch 실패: $($_.Exception.Message)"
- return
- }
- # convert
- # openapi-to-postmanv2 5.x 옵션:
- # folderStrategy=Tags tag 별 폴더 분류
- # enableOptionalParameters optional query/header 포함
- # includeAuthInfoInExample Bearer auth header 자동
- $opts = "folderStrategy=Tags,enableOptionalParameters=true,includeAuthInfoInExample=true"
- & npx -y openapi-to-postmanv2@5 -s $tmpFile -o $outFile -p -O $opts 2>&1 | Out-Host
- if (Test-Path $outFile) {
- $outSize = (Get-Item $outFile).Length
- $col = Get-Content $outFile -Raw | ConvertFrom-Json
- $folders = $col.item.Count
- function CountReq($items) {
- $n = 0
- foreach ($it in $items) {
- if ($it.request) { $n++ }
- elseif ($it.item) { $n += CountReq $it.item }
- }
- return $n
- }
- $reqs = CountReq $col.item
- Write-Ok "$OutName.postman_collection.json — $folders folders / $reqs requests / $outSize bytes"
- } else {
- Write-Fail "$OutName 변환 결과 파일이 생성되지 않음"
- }
- }
- if (-not $SkipInternal) { Convert-Swagger -DocName "internal" -OutName "ANTOOZA-Internal-API" }
- Write-Host ""
- Write-Step "완료 — Postman 에서 collections/*.postman_collection.json 을 import 하세요"
|