update.ps1 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. # ============================================================================
  2. # ANTOOZA Postman Collection 갱신 스크립트
  3. #
  4. # 사용법:
  5. # 1. 백엔드 실행 (다른 터미널)
  6. # cd E:\workspace\antooza\Backend
  7. # dotnet run --project Web.Api
  8. #
  9. # 2. 이 스크립트 실행
  10. # cd E:\workspace\antooza\Backend\Web.Api\postman
  11. # pwsh ./update.ps1
  12. #
  13. # 옵션:
  14. # -ApiBase <url> 기본값: https://localhost:4000
  15. # -SkipInternal internal swagger 변환 생략
  16. #
  17. # 결과:
  18. # collections/ANTOOZA-Internal-API.postman_collection.json (내부 /api/*)
  19. #
  20. # 요구사항:
  21. # - Node.js (npx 포함) — openapi-to-postmanv2 를 npx 로 1회성 실행
  22. # - 실행 중인 로컬 백엔드 (internal swagger 는 Production 에 차단되어 로컬 필수)
  23. # ============================================================================
  24. [CmdletBinding()]
  25. param(
  26. [string]$ApiBase = "https://localhost:4000",
  27. [switch]$SkipInternal
  28. )
  29. $ErrorActionPreference = "Stop"
  30. $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
  31. Set-Location $scriptDir
  32. function Write-Step($msg) { Write-Host "[$(Get-Date -Format 'HH:mm:ss')] $msg" -ForegroundColor Cyan }
  33. function Write-Ok($msg) { Write-Host " [OK] $msg" -ForegroundColor Green }
  34. function Write-Fail($msg) { Write-Host " [!!] $msg" -ForegroundColor Red }
  35. # 1) 백엔드 health check
  36. Write-Step "백엔드 health check ($ApiBase/health)"
  37. try {
  38. $r = Invoke-WebRequest -Uri "$ApiBase/health" -SkipCertificateCheck -TimeoutSec 5 -UseBasicParsing
  39. if ($r.StatusCode -ne 200) {
  40. Write-Fail "health 응답 $($r.StatusCode) — 백엔드 실행 상태 확인 필요"
  41. exit 1
  42. }
  43. Write-Ok "백엔드 정상 응답"
  44. } catch {
  45. Write-Fail "백엔드 접근 실패: $($_.Exception.Message)"
  46. Write-Host " 먼저 다른 터미널에서 다음 명령을 실행하세요:" -ForegroundColor Yellow
  47. Write-Host " cd E:\workspace\antooza\Backend; dotnet run --project Web.Api" -ForegroundColor Yellow
  48. exit 1
  49. }
  50. # 2) Node/npx 사용 가능 확인
  51. Write-Step "Node.js / npx 확인"
  52. $nodeVer = (& node -v) 2>$null
  53. $npxVer = (& npx --version) 2>$null
  54. if (-not $nodeVer -or -not $npxVer) {
  55. Write-Fail "Node.js 또는 npx 가 없습니다. https://nodejs.org 에서 설치하세요."
  56. exit 1
  57. }
  58. Write-Ok "node $nodeVer / npx $npxVer"
  59. # 3) collections 폴더 보장
  60. $colDir = Join-Path $scriptDir "collections"
  61. if (-not (Test-Path $colDir)) {
  62. New-Item -ItemType Directory -Path $colDir | Out-Null
  63. }
  64. function Convert-Swagger {
  65. param(
  66. [string]$DocName, # internal
  67. [string]$OutName # ANTOOZA-Internal-API
  68. )
  69. Write-Step "$DocName swagger 변환"
  70. $swaggerUrl = "$ApiBase/swagger/$DocName/swagger.json"
  71. $tmpFile = Join-Path $env:TEMP "antooza-$DocName.json"
  72. $outFile = Join-Path $colDir "$OutName.postman_collection.json"
  73. # fetch
  74. try {
  75. Invoke-WebRequest -Uri $swaggerUrl -SkipCertificateCheck -OutFile $tmpFile -UseBasicParsing | Out-Null
  76. $size = (Get-Item $tmpFile).Length
  77. Write-Ok "$swaggerUrl => $size bytes"
  78. } catch {
  79. Write-Fail "swagger fetch 실패: $($_.Exception.Message)"
  80. return
  81. }
  82. # convert
  83. # openapi-to-postmanv2 5.x 옵션:
  84. # folderStrategy=Tags tag 별 폴더 분류
  85. # enableOptionalParameters optional query/header 포함
  86. # includeAuthInfoInExample Bearer auth header 자동
  87. $opts = "folderStrategy=Tags,enableOptionalParameters=true,includeAuthInfoInExample=true"
  88. & npx -y openapi-to-postmanv2@5 -s $tmpFile -o $outFile -p -O $opts 2>&1 | Out-Host
  89. if (Test-Path $outFile) {
  90. $outSize = (Get-Item $outFile).Length
  91. $col = Get-Content $outFile -Raw | ConvertFrom-Json
  92. $folders = $col.item.Count
  93. function CountReq($items) {
  94. $n = 0
  95. foreach ($it in $items) {
  96. if ($it.request) { $n++ }
  97. elseif ($it.item) { $n += CountReq $it.item }
  98. }
  99. return $n
  100. }
  101. $reqs = CountReq $col.item
  102. Write-Ok "$OutName.postman_collection.json — $folders folders / $reqs requests / $outSize bytes"
  103. } else {
  104. Write-Fail "$OutName 변환 결과 파일이 생성되지 않음"
  105. }
  106. }
  107. if (-not $SkipInternal) { Convert-Swagger -DocName "internal" -OutName "ANTOOZA-Internal-API" }
  108. Write-Host ""
  109. Write-Step "완료 — Postman 에서 collections/*.postman_collection.json 을 import 하세요"