Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
フロントエンドとバックエンドのコミュニケーションをスムーズにするスキーマ駆動開発
Search
shimakaze-git
December 10, 2023
Programming
590
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
1.2k
クリーンアーキテクチャのリポジトリパターン - Pythonでの実装
shimakaze_soft
1
6.3k
lt20221030.pdf
shimakaze_soft
0
190
Dependabotを使って 運用しているおはなし
shimakaze_soft
0
2.3k
DjangoCongressJP 2019/2020 & 今年にPyConJP初登壇できたはなし
shimakaze_soft
0
480
GAEによるPythonWEBアプリケーションの高速開発
shimakaze_soft
0
3.3k
FlaskとDjango以外のAPI開発の選択肢
shimakaze_soft
0
550
Python で Dependency Injection(DI) をやるには?
shimakaze_soft
1
3.8k
FalconAPI開発にいいよ!
shimakaze_soft
0
780
Other Decks in Programming
See All in Programming
AWS Step Functions 大規模並列の壁を越える / jaws-sonic-2026-niigata-step-functions
kasacchiful
PRO
1
430
iOS開発×AI駆動開発 〜最近使って便利だったスキルの話〜
nogu66
0
140
業務時間外もAIに働いてもらう話
colorful12
3
10k
Security issues being discussed on Web Platforms
petamoriken
0
620
Deep dive into the select statement (GopherCon UK)
jespino
0
170
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
290
Gmail/Google DriveをトリガーにAIエージェントを動かそう! / Run AI agents with Gmail/Google Drive as triggers!
har1101
3
490
市販E-Readerを乗っ取れ 〜Embedded Swiftで電子ペーパーガジェットを制御する〜
trickart
0
160
LoopHub - ローカルで動く GitHub で、AI と共同開発
jugyo
1
490
『寄り添うラジオ』をAIで作る 体験価値から逆算した、会話しないUXと品質設計
theoriatec2024
3
150
MIZARU@SPAJAM2026 第二回予選
1901drama
0
110
【高い買い物LT会】初任給で話題の国産フィジカルAIを買った話
akagami
PRO
0
140
Featured
See All Featured
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
660
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
Evolving SEO for Evolving Search Engines
ryanjones
0
280
How STYLIGHT went responsive
nonsquared
100
6.3k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
240
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
240
Faster Mobile Websites
deanohume
310
32k
Measuring Dark Social's Impact On Conversion and Attribution
stephenakadiri
2
270
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Lightning Talk: Beautiful Slides for Beginners
inesmontani
PRO
2
680
Lightning talk: Run Django tests with GitHub Actions
sabderemane
0
250
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
4
620
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