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
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.1k
クリーンアーキテクチャのリポジトリパターン - 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
540
Python で Dependency Injection(DI) をやるには?
shimakaze_soft
1
3.8k
FalconAPI開発にいいよ!
shimakaze_soft
0
780
Other Decks in Programming
See All in Programming
Flow は今どうなっているか
mizdra
PRO
0
830
DroidKaigi 2026 「個人開発という実験場: Android エンジニアが手にする4つの自由」
slashnephy
0
180
{ Android | Kotlin } Gradle Plugin in 2026
ryunen344
1
240
レビュー履歴をAIに食わせて、 Compose移行を加速するs
shihochan
0
260
Hello, Hiroshima Geospatial Data! — Exploring DoboX with Python
ra0kley
0
150
Press start. Python's next generation.
willingc
PRO
3
300
Webエンジニアなのにブラウザの仕組みがわからないので、Pythonで自作してみた
tatsuki12
4
1.6k
いまどきの Codex で開発する visionOS アプリの開発スタイルについて
karad
0
180
Gmail/Google DriveをトリガーにAIエージェントを動かそう! / Run AI agents with Gmail/Google Drive as triggers!
har1101
3
460
高専キャリア LT 発表内容
crysta1221
6
5.4k
Swift愛好会と私(ウホーイ) / Swift Fan Club and Uhooi
uhooi
0
120
片田舎のおっさん、 Swift Buildのダイアモンド問題解決の不具合修正PRを出すが、解決方法がキャッシュをしないようにすることであり、ビルド時間が伸びると言われてマージされないので高速化もする/swiftbuild
yimajo
0
340
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
Public Speaking Without Barfing On Your Shoes - THAT 2023
reverentgeek
1
550
Designing Experiences People Love
moore
143
24k
HU Berlin: Industrial-Strength Natural Language Processing with spaCy and Prodigy
inesmontani
PRO
0
680
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Exploring anti-patterns in Rails
aemeredith
3
490
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
810
Pawsitive SEO: Lessons from My Dog (and Many Mistakes) on Thriving as a Consultant in the Age of AI
davidcarrasco
0
230
The Illustrated Children's Guide to Kubernetes
chrisshort
51
53k
Raft: Consensus for Rubyists
vanstee
141
7.7k
The Spectacular Lies of Maps
axbom
PRO
1
960
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
320
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