"매 API 의 shape (path, method, schema, error, auth) 을 매 machine-readable spec 으로 매 먼저 정의하고 매 그 후 server/client 가 매 그것을 따른다." OpenAPI 3.1 (REST), gRPC .proto, GraphQL SDL, AsyncAPI (event), JSON Schema 가 매 dominant. 2026 현재 매 LLM 이 매 spec 을 읽어 매 client / mock / test 를 매 generate — 매 contract-first 가 매 AI 시대의 매 default.
매 핵심
매 contract-first vs code-first
Contract-first: 매 spec → 매 server stub + 매 client SDK. 매 multi-team / multi-language 의 default.
Code-first: 매 code → 매 spec generated (FastAPI, NestJS Swagger). 매 single team 에서 매 빠름.
2026 추세: 매 contract-first 가 매 LLM-friendly + 매 mock-driven dev 에 유리.
매 standard 별 사용처
OpenAPI 3.1: 매 REST/HTTP. 매 JSON Schema 2020-12 align.
gRPC + protobuf: 매 internal high-perf, 매 strong typing.
GraphQL SDL: 매 client-driven query, 매 BFF.
AsyncAPI 3: 매 Kafka / NATS / WebSocket event.
JSON Schema: 매 payload validation, 매 LLM structured output.
매 contract testing
Provider tests: 매 server 가 매 spec 을 만족하는지 검증 (매 schemathesis, dredd, prism).
Consumer-driven contracts: 매 Pact — 매 client 가 매 expectation 을 매 publish, 매 server 가 매 verify.
schemathesis run openapi.yaml --base-url=http://localhost:8000 \
--checks=all --hypothesis-deadline=2000
7) Pact consumer test (TS)
import{Pact}from'@pact-foundation/pact';constprovider=newPact({consumer:'web',provider:'orders'});awaitprovider.addInteraction({state:'order 1 exists',uponReceiving:'a get for order 1',withRequest:{method:'GET',path:'/v1/orders/1'},willRespondWith:{status: 200,body:{id:'1',total: 99}}});
언제: 매 spec → SDK / mock / test scaffold 자동 생성, 매 spec lint, 매 changelog diff.
언제 X: 매 LLM 이 매 spec 을 매 invent — 매 source-of-truth 는 매 git-tracked spec file.
❌ 안티패턴
Spec drift: 매 server 가 매 spec 과 매 다름. 매 schemathesis CI 로 차단.
No versioning: 매 breaking change 를 매 same path 에 push. 매 /v1 → /v2 또는 매 deprecated header.
Anyof everywhere: 매 spec 이 매 너무 permissive → 매 client 의 매 type narrowing 불가.
Code-first without lint: 매 generated spec 이 매 inconsistent (매 nullable, 매 enum).
Mock-only test: 매 contract test 없이 매 mock 만 사용 → 매 prod fail.