test: 서버 OpenAPI 스펙과 호출 경로를 대조한다 - #99
Merged
Merged
Conversation
경로는 문자열이라 타입 검사도 린트도 불일치를 잡지 못한다. 서버에서 지운 경로
(/oauth2/kakao/auth-url)를 계속 불러 메인 화면 카카오 로그인이 무반응이던 일이 있었다.
- openapi/openapi.json: 서버가 고정해 둔 스펙의 사본 (원본은 서버 저장소 docs/api/openapi.json)
- openapi-contract.test.ts: src/apis/*.ts 의 호출을 스펙과 대조. PR CI 에 포함된다.
경로 변수 자리는 세그먼트 와일드카드로 비교한다 — 프런트의 ${type} 이 경로 변수인지
리터럴 값(privacy-policy)인지 문자열만 보고는 구분할 수 없다. (첫 실행에서 실제로 오탐이 났다)
검사가 무력화되지 않게 "지워진 옛 경로가 스펙에 없다" 도 함께 고정했다.
- npm run sync:openapi: 서버 main 에서 사본 갱신. OPENAPI_SRC 로 로컬 파일도 가능.
내용이 스펙 모양이 아니면(404 HTML 등) 실패시킨다.
- openapi-drift 워크플로: 매일 서버 main 스펙을 새로 가져와 대조. PR CI 는 사본으로 검사하므로
(결과가 서버 저장소 상태에 흔들리면 안 된다) 사본이 낡는 문제는 이쪽이 잡는다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #98
서버: CareCode-Repo/CareCode_Interface#127 (머지됨 — 스펙 파일이
docs/api/openapi.json에 있다)무엇
openapi/openapi.jsonopenapi-contract.test.tssrc/apis/*.ts호출을 스펙과 대조. PR CI 포함npm run sync:openapiOPENAPI_SRC로 로컬 파일도 가능)openapi-drift워크플로판단 두 가지
사본을 두는 이유 — PR CI 결과가 서버 저장소 상태에 따라 흔들리면 안 된다. 대신 사본이 낡는 문제를 매일 도는 워크플로가 따로 본다(무관한 PR 을 막지 않으면서 하루 안에 드러난다).
경로 변수 비교 — 세그먼트 와일드카드로 맞춘다. 처음에는 정확히 비교했는데
GET /legal/${type}이 오탐으로 걸렸다.type은 경로 변수가 아니라 리터럴 값(privacy-policy/terms)이고, 문자열만 보고는 구분할 수 없다.검사가 살아 있는지도 확인한다
"지워진 옛 경로(
/oauth2/kakao/auth-url)가 스펙에 없다" 를 테스트로 고정했다. 스펙이 빈 파일로 바뀌거나 비교가 무력화되면 이 테스트가 먼저 깨진다.테스트
npm run sync:openapi로컬/원격 두 경로 모두 확인 (머지 전에는 404 로 올바르게 실패했다)