Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
フロントエンドとバックエンドのコミュニケーションをスムーズにするスキーマ駆動開発
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
shimakaze-git
December 10, 2023
Programming
570
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
フロントエンドとバックエンドのコミュニケーションをスムーズにするスキーマ駆動開発
shimakaze-git
December 10, 2023
More Decks by shimakaze-git
See All by shimakaze-git
DjangoとFastAPIによる 実践認証技術
shimakaze_soft
0
940
クリーンアーキテクチャのリポジトリパターン - Pythonでの実装
shimakaze_soft
1
6.2k
lt20221030.pdf
shimakaze_soft
0
180
Dependabotを使って 運用しているおはなし
shimakaze_soft
0
2.3k
DjangoCongressJP 2019/2020 & 今年にPyConJP初登壇できたはなし
shimakaze_soft
0
470
GAEによるPythonWEBアプリケーションの高速開発
shimakaze_soft
0
3.3k
FlaskとDjango以外のAPI開発の選択肢
shimakaze_soft
0
530
Python で Dependency Injection(DI) をやるには?
shimakaze_soft
1
3.8k
FalconAPI開発にいいよ!
shimakaze_soft
0
760
Other Decks in Programming
See All in Programming
技術記事、 専門家としてのプログラマ、 言語化
mizchi
13
6.6k
決定論的オーケストレーションの設計と実装 / Design and Implementation of Deterministic Orchestration
nrslib
4
1.5k
気づいたらRubyで100作品 ー クリエイティブコーディングが生活の一部になるまで / 100 Ruby Sketches Later: How Creative Coding Became Part of My Life
chobishiba
3
610
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
190
そのテスト、説明できますか?~LWテスト戦略FW~のご紹介
nakahara
0
170
ADKを使って簡単にAIエージェントを作ってみよう
k1mu21
0
280
TypeScript+Orvalで実現する型安全かつ堅牢でスケーラブルなマルチチャネル通知基盤 / TSKaigi Night talks ~after conference~
d0riven
0
370
Inside Stream API
skrb
1
800
Hunting Vulnerabilities in Symfony with LLMs
vinceamstoutz
0
560
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
760
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
410
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.3k
Featured
See All Featured
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
870
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
310
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
62
55k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
170
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
55k
Game over? The fight for quality and originality in the time of robots
wayneb77
1
210
Abbi's Birthday
coloredviolet
3
8.3k
Code Review Best Practice
trishagee
74
20k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.2k
Done Done
chrislema
186
16k
Transcript
フロントエンドとバックエンドのコミュニケーション をスムーズにするスキーマ駆動開発 エンジニアの輪@東京 2023/12/10 @shimakaze_soft shimakaze-soft 1
Who are you? おまえだれよ? Twitter: @shimakaze_soft GitHub: shimakaze-git toB系のプロダクトを開発するスタートアップでテックリード的な立場 趣味
サッカー観戦 歴史 shimakaze-soft 2
バックエンド & インフラエンジニア Django, FastAPI Pulumi OSS PyConJP 2023 当日Staff
DjangoCongress 2018~2021(Staff) shimakaze-soft 3
スキーマ駆動開発ってご存知ですか? shimakaze-soft 4
フロントエンドとバックエンドのエンジニア間でこん なやり取りありませんか? shimakaze-soft 5
フロントエンド バックエンドエンジニアが作成したAPIのレスポンスとリクエストボディのスキー マが複雑すぎてフロントの実装が大変 バックエンド フロントエンドが要求したスキーマがかなり複雑すぎて、バックエンドの処理が 大変すぎる。パフォーマンスの観点でもあまり良くないスキーマを要求される。 shimakaze-soft 6
例 : ユーザーの一覧のページを作成するとする shimakaze-soft 7
フロントエンドエンジニアが欲しいレスポンスのスキ ーマ { "users": [ { "id": 1, "name": "test1"
}, { "id": 2, "name": "test2" } ] } shimakaze-soft 8
バックエンドエンジニアが作成したレスポンスのスキ ーマ { "ids": [ 1, 2 ], "names": [
"test1", "test2" ] } shimakaze-soft 9
フロントエンド側の整形処理がかなり大変になる { "ids": [ 1, 2 ], "names": [ "test1",
"test2" ] } shimakaze-soft 10
shimakaze-soft 11
APIのスキーマをどうするかは揉めがち shimakaze-soft 12
API全般の開発の主導権はバックエンドエンジニアが持つ事が多い ビジネスロジックをどちらで持つかにも関わる パフォーマンスの観点で最適なスキーマもある バックエンド主導のスキーマに決まりやすい shimakaze-soft 13
フロントエンドとバックエンドのスキーマの違いがも たらす課題 バックエンドがAPIが完成するまでAPIを叩くところの実装を待たなければいけな い こういうレスポンスが返ってくる。こういうリクエストボディを投げるという想定 で実装しなければいけない 実際に作られたAPIのスキーマが事前に話し合われたものと違った shimakaze-soft 14
どう解決する? shimakaze-soft 15
API設計書をExcelで作る? API設計書と実際の実装が違っていたら?それをどうやって確認す る? shimakaze-soft 16
OpenAPIによるスキーマ駆動開発 shimakaze-soft 17
OpenAPIとは shimakaze-soft 18
OpenAPIとは 旧称はSwaggerと呼ばれていた。 APIの設計、開発、および利用に関する標準化された仕様の一つ。 この仕様は、RESTfulなAPIの記述を可能にし、APIのエンドポイント、リクエスト・レ スポンスの形式、認証方法などを文書化するための仕様。 JSONやYAML形式でAPIの設計情報を表現し、開発者やクライアントが理解しやすい 形でAPIを提供することができます。 OpenAPIの仕様に基づいてドキュメントを生成す るツールも提供されている。 shimakaze-soft
19
/api/users というエンドポイントを想定 openapi: 3.0.0 info: title: Sample API Response version:
1.0.0 paths: /users: get: summary: Get Users responses: '200': description: Successful response content: application/json: schema: type: object properties: users: type: array items: type: object properties: id: type: integer example: 1 name: type: string example: "test" shimakaze-soft 20
モックのAPIを構築できる OpenAPIのファイルを元にモックサーバーを構築できる version: "3" services: mock: image: stoplight/prism:3 container_name: auth_api_mock
platform: linux/amd64 tty: true ports: - 7501:4010 volumes: - ./openapi/openapi.yml:/openapi.yml:cached command: | mock -h 0.0.0.0 /openapi.yml shimakaze-soft 21
実際にAPIにリクエストを行う $ curl 'http://localhost:7501/users' エンドポイントで以下が返ってくる { users: [ {"id": 1,
"name": "test"}, {"id": 2, "name": "test"}, ] } shimakaze-soft 22
フロントエンドエンジニアもAPI設計をする shimakaze-soft 23
具体的な開発プロセス YMLでOpenAPI形式のAPIのスキーマを定義する そのファイルをGitHubのPRに出す shimakaze-soft 24
PRを出す際のルール フロントエンドの人が作成した場合はバックエンドの人がReview バックエンドの人が作成した場合はフロントエンドの人がReview 必ずバックエンドとフロントエンドの両者がPRを見る PRがマージされた = そのスキーマにお互いが合意した shimakaze-soft 25
急遽スキーマを変更したくなる場合がある バックエンドの実装を修正せずに、スキーマを修正してフロントエンドの実装が 可能 shimakaze-soft 26
ymlのスキーマとバックエンドの実装の差分をどうす るか 設計書として作成したymlのスキーマとバックエンドの実際の実装に差分が出る可能性 の問題どうする? shimakaze-soft 27
OpenAPIの差分比較ツールを使用 shimakaze-soft 28
oasdiff 二つのOpenAPI形式のファイルを比較して差分がないかをチェックしてくれるツール # Mac $ brew tap tufin/homebrew-tufin $ brew
install oasdiff $ go install github.com/tufin/oasdiff@latest shimakaze-soft 29
バックエンドの実装からスキーマを取り出す 今回はFastAPIを想定 shimakaze-soft 30
FastAPIにはOpenAPIの機能がデフォルトである shimakaze-soft 31
FastAPIにはOpenAPIの機能がデフォルトである openapi.json をダウンロード' shimakaze-soft 32
oasdiffを使用して差分を比較する $ oasdiff diff openapi.json openapi.yml --format text shimakaze-soft 33
実装とスキーマに差分が出る New Endpoints: 10 PUT /api/users GET /api/usrs Deleted Endpoints:
None Modified Endpoints: None GET /api/users/{usre_id} Responses changed Modified response: 200 Content changed Modified media type: application/json Schema changed Properties changed Modified property: general Required changed New required property: stores Deleted required property: store Properties changed New property: stores Deleted property: store shimakaze-soft 34
apidog apidogというツールもおすすめ https://apidog.com/jp/ shimakaze-soft 35
エンジニア募集 技術スタック バックエンド: Django, FastAPI フロントエンド: Next.js, Typescript インフラ: AWS,
Pulumi https://jobs.forkwell.com/recustomer/jobs/23462 shimakaze-soft 36