Skip to content

feat(api): server swagger docs - #102

Merged
ehlung merged 6 commits into
developfrom
feature/swagger-docs-deploy
Jun 29, 2026
Merged

feat(api): server swagger docs#102
ehlung merged 6 commits into
developfrom
feature/swagger-docs-deploy

Conversation

@meteorqz6

@meteorqz6 meteorqz6 commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Serve Swagger UI from the API at /api/docs
  • Serve raw OpenAPI JSON at /api/openapi.json
  • Inject API_PUBLIC_BASE_URL as the first OpenAPI server for deployed environments
  • Add missing implemented Staffing Rules endpoints to docs/openapi.yaml
  • Update Swagger sharing/deployment notes

Verification

  • corepack pnpm build:api
  • corepack pnpm --filter @fragment/api lint
  • corepack pnpm --filter @fragment/api typecheck
  • corepack pnpm --filter @fragment/api test

Deploy Notes

  • Railway should set API_PUBLIC_BASE_URL=https://<api-domain>/api
  • After merge to main, verify /api/docs and /api/openapi.json on the deployed API domain

Summary by CodeRabbit

  • New Features
    • API 문서가 웹 UI로 제공되며, 원본 OpenAPI JSON(/api/openapi.json)도 확인할 수 있습니다.
    • 최소 인원 조건(StaffingRules) 관련 조회/생성/수정/삭제 기능이 공개 API에 추가되었습니다.
  • Documentation
    • Swagger/OpenAPI 문서 범위를 최신 공개 API 기준으로 갱신했습니다.
  • Bug Fixes
    • 문서의 서버 URL을 API_PUBLIC_BASE_URL 환경 변수로 정확히 반영하도록 개선했습니다.

@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
final-project-web Skipped Skipped Jun 29, 2026 7:54pm

@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@meteorqz6, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 46 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 21fdbce3-f29f-4d96-9492-df237e5ef3e1

📥 Commits

Reviewing files that changed from the base of the PR and between 49ee4c1 and ddbc50a.

📒 Files selected for processing (1)
  • apps/api/test/docs.routes.test.ts

Walkthrough

docs/openapi.yaml에 StaffingRules CRUD 엔드포인트와 관련 스키마를 추가하고, API 서버가 해당 YAML을 파싱해 /api/openapi.json/api/docs로 서빙하도록 연결했다. API_PUBLIC_BASE_URL 처리, 테스트, 빌드 스크립트, SWAGGER 문서도 함께 갱신됐다.

Changes

Swagger UI 서빙 및 StaffingRules OpenAPI 정의

Layer / File(s) Summary
StaffingRules OpenAPI 스키마 및 엔드포인트 정의
docs/openapi.yaml
/staffing-rules/staffing-rules/{ruleId}에 CRUD 연산을 추가하고, RuleId 파라미터, 도메인 응답, 최소 인원 조건 스키마를 정의했다. 기존 일부 409 응답 참조도 도메인별 컴포넌트로 분리됐다.
getOpenApiDocument: YAML 파싱 및 서버 URL 교체
apps/api/src/openapi.ts, .env.example
docs/openapi.yaml을 YAML로 읽어 OpenAPI 문서를 만들고, API_PUBLIC_BASE_URL이 있으면 servers를 정규화된 URL로 보정하도록 했다. .env.example에 해당 예시 값도 추가됐다.
Swagger UI 및 OpenAPI JSON 라우트 등록
apps/api/src/app.ts, apps/api/package.json
createApp에서 문서를 캐시하고 /api/openapi.json, /api/docs를 등록했으며, Swagger UI와 YAML 파싱 관련 의존성을 추가했다.
문서 라우트 테스트 및 빌드 스크립트 정리
apps/api/test/docs.routes.test.ts, apps/api/package.json, package.json
Swagger UI 응답, OpenAPI JSON의 서버 URL 주입, 예시 응답 정합성을 검증하는 테스트를 추가하고, API 빌드/타입체크 스크립트를 단순화했다.
SWAGGER.md 문서 갱신
docs/SWAGGER.md
현재 OpenAPI 문서화 범위와 /api/openapi.json, API_PUBLIC_BASE_URL 기준, Swagger UI 사용 조건을 정리했다.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning 요약·검증은 있으나 템플릿의 개요, 변경 사항, 유형, 영향 범위, 테스트 방법, 체크리스트가 거의 비어 있습니다. 템플릿대로 개요, Closes #이슈번호, 변경 사항, 변경 유형, 영향 범위, 테스트 방법, 체크리스트를 채워 주세요.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed 제목이 Swagger 문서 제공이라는 핵심 변경을 정확히 요약합니다.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/swagger-docs-deploy

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/api/src/app.ts`:
- Around line 44-48: Remove the Swagger UI authorization persistence from the
setup in app.ts: the swaggerUi.setup call currently passes
swaggerOptions.persistAuthorization: true, which stores auth data in browser
storage. Update that swaggerOptions block so persistAuthorization is omitted or
set to false, keeping the rest of the SwaggerUi setup unchanged.

In `@docs/openapi.yaml`:
- Around line 464-523: The StaffingRules OpenAPI contract is missing the
domain-specific 400 error cases for create/update minimum staffing rules. Update
the minimum staffing rule paths in openapi.yaml so the
`createMinimumStaffingRule` and `updateMinimumStaffingRule` responses explicitly
document `CLOSED_DAY` and `INVALID_TIME_RANGE` alongside the existing
`ValidationError`, using either dedicated response components or clear examples
under the `MinimumStaffingRule` endpoints. Keep the change anchored around
`createMinimumStaffingRule`, `updateMinimumStaffingRule`, and the `400` response
definitions so Swagger exposes the same error contract as docs/API.md.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 3c240d55-d2c9-40c2-9fff-2acfbffe9408

📥 Commits

Reviewing files that changed from the base of the PR and between d85941a and 1211dad.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (8)
  • .env.example
  • apps/api/package.json
  • apps/api/src/app.ts
  • apps/api/src/openapi.ts
  • apps/api/test/docs.routes.test.ts
  • docs/SWAGGER.md
  • docs/openapi.yaml
  • package.json

Comment thread apps/api/src/app.ts Outdated
Comment thread docs/openapi.yaml

@meteorqz6 meteorqz6 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed the review comments in 90c2e74.

  • Removed Swagger UI persistAuthorization so auth data is not persisted in browser storage.
  • Added MinimumStaffingRuleBadRequest OpenAPI response examples for VALIDATION_ERROR, CLOSED_DAY, and INVALID_TIME_RANGE.
  • Added route tests covering both changes.

Verified with:

  • corepack pnpm --filter @fragment/api lint
  • corepack pnpm --filter @fragment/api typecheck
  • corepack pnpm --filter @fragment/api test
  • corepack pnpm build:api

@meteorqz6
meteorqz6 changed the base branch from main to develop June 29, 2026 18:52

@meteorqz6 meteorqz6 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the mismatched Swagger error examples in 5e12f4b.

What changed:

  • Added explicit examples for common 400, 401, 403, and 404 response components so Swagger no longer falls back to the generic VALIDATION_ERROR schema example.
  • Added dedicated 409 response components for duplicate email, organization already exists, draft already exists, and schedule conflict.
  • Added a docs route test that walks all OpenAPI response examples and fails if example.statusCode does not match the documented HTTP response code.

Verified with:

  • corepack pnpm --filter @fragment/api lint
  • corepack pnpm --filter @fragment/api typecheck
  • corepack pnpm --filter @fragment/api test
  • corepack pnpm build:api

@meteorqz6
meteorqz6 force-pushed the feature/swagger-docs-deploy branch from 5e12f4b to 49ee4c1 Compare June 29, 2026 19:40

@meteorqz6 meteorqz6 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the CI failure in 49ee4c1.

Root cause:

  • The Lint & Type Check job failed at pnpm format:check, not API lint/typecheck.
  • apps/api/test/docs.routes.test.ts needed Prettier formatting after the OpenAPI response-example test was added.

Re-verified locally with the CI sequence:

  • corepack pnpm format:check
  • corepack pnpm --filter @fragment/shared build
  • corepack pnpm --filter @fragment/database db:generate
  • corepack pnpm --filter @fragment/database build
  • corepack pnpm --filter @fragment/web lint (existing warning only, exit 0)
  • corepack pnpm --filter @fragment/web typecheck
  • corepack pnpm --filter @fragment/web test
  • corepack pnpm --filter @fragment/api lint
  • corepack pnpm --filter @fragment/api typecheck
  • corepack pnpm --filter @fragment/api test

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@apps/api/test/docs.routes.test.ts`:
- Around line 22-31: The docs route test currently skips over broken $ref
responses because resolveOpenApiRef() can return undefined and the loop just
continues in the docs.routes.test.ts check. Update the response validation in
the block that iterates over responses so that when responseDefinition.$ref is
present, the test first asserts the ref resolves successfully before checking
application/json; use resolveOpenApiRef, responseDefinition.$ref, and
jsonContent as the key symbols to locate the logic. This should fail the test
immediately for any unresolved `#/components/responses/`... reference instead of
silently passing.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 17ef2712-d001-40d9-b1d5-67b4f6322723

📥 Commits

Reviewing files that changed from the base of the PR and between 1211dad and 49ee4c1.

📒 Files selected for processing (3)
  • apps/api/src/app.ts
  • apps/api/test/docs.routes.test.ts
  • docs/openapi.yaml
💤 Files with no reviewable changes (1)
  • apps/api/src/app.ts

Comment thread apps/api/test/docs.routes.test.ts

@meteorqz6 meteorqz6 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the latest CodeRabbit comment and decided to apply it.

Reason:

  • The finding is valid: if an OpenAPI response $ref is misspelled, the existing helper could resolve to undefined and skip the check because jsonContent was missing.

Change pushed in ddbc50a:

  • Assert that every response $ref resolves before checking JSON examples.

Verified:

  • corepack pnpm format:check
  • corepack pnpm --filter @fragment/api test -- docs.routes.test.ts

@ehlung
ehlung merged commit f591396 into develop Jun 29, 2026
4 checks passed
@ehlung
ehlung deleted the feature/swagger-docs-deploy branch June 29, 2026 20:03
@meteorqz6 meteorqz6 changed the title feat(api): serve swagger docs feat(api): server swagger docs Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants