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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
shimakaze-git
December 10, 2023
Programming
560
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.1k
lt20221030.pdf
shimakaze_soft
0
180
Dependabotを使って 運用しているおはなし
shimakaze_soft
0
2.3k
DjangoCongressJP 2019/2020 & 今年にPyConJP初登壇できたはなし
shimakaze_soft
0
460
GAEによるPythonWEBアプリケーションの高速開発
shimakaze_soft
0
3.2k
FlaskとDjango以外のAPI開発の選択肢
shimakaze_soft
0
520
Python で Dependency Injection(DI) をやるには?
shimakaze_soft
1
3.8k
FalconAPI開発にいいよ!
shimakaze_soft
0
760
Other Decks in Programming
See All in Programming
運用エージェントは "作る" から "育てる" へ - 記憶と自己進化の3層設計パターン / self-evolving-agents-three-layer-agent-design
gawa
12
3.6k
AI時代のUIはどこへ行く?その2!
yusukebe
21
7k
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.2k
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
150
[2026年度第1回ORセミナー] 計画最適化ベンチャーと競技プログラミング人材
terryu16
0
260
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
260
依存関係から依存物へ―Dependencyという言葉の歴史をひも解く
j_lee
0
110
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
320
キャリア迷子上等 ─ "ない道"は自分で作ればいい
16bitidol
3
2k
TypeScript+Orvalで実現する型安全かつ堅牢でスケーラブルなマルチチャネル通知基盤 / TSKaigi Night talks ~after conference~
d0riven
0
320
Lessons from Spec-Driven Development
simas
PRO
0
170
JavaDoc 再入門
nagise
0
320
Featured
See All Featured
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
850
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.2k
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
200
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.2k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
360
30k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
65
56k
Code Reviewing Like a Champion
maltzj
528
40k
Building an army of robots
kneath
306
46k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
180
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
330
Reflections from 52 weeks, 52 projects
jeffersonlam
356
21k
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