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
Generate a rust client code by OpenAPI Generator
Search
Kentaro Matsumoto
August 16, 2024
Programming
790
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Generate a rust client code by OpenAPI Generator
Kentaro Matsumoto
August 16, 2024
More Decks by Kentaro Matsumoto
See All by Kentaro Matsumoto
claude_code.pdf
matsu7874
5
7.6k
Marpを使って登壇資料を作る
matsu7874
0
2.4k
ざっと理解するRust 2024 Edition
matsu7874
0
1.9k
プリントデバッグを失敗させないテクニック
matsu7874
1
500
社外を巻き込んだ勉強会を定期開催するコツ
matsu7874
0
250
actix-webを使った開発のハマリポイントを避けたい
matsu7874
0
1.2k
our test strategy on actix-web app
matsu7874
0
1.8k
roadmap to rust 2024
matsu7874
0
2.2k
Rust tutorial for Pythonista
matsu7874
2
1.5k
Other Decks in Programming
See All in Programming
Loosening the Reins: Go Generics Get More Flexible
kuro_kurorrr
0
350
承認済みなのに差戻しできてしまうバグ、型で潰せます
shinchit
0
120
レビュー履歴をAIに食わせて、 Compose移行を加速するs
shihochan
0
240
freeeにおけるEvalsの実践例の紹介
freee
PRO
0
160
AI駆動開発にグラフDBを重ねてみた
satoshi256kbyte
1
400
Discordを用いたラボオートメーション関連情報収集の自動化
noguhiro2002
0
470
楽しそうなつよつよエンジニアと目が死んでる僕/A brilliant engineer having a blast, and dead-eyed me.
3l4l5
2
260
まずはプロンプトガイドを読もう、話はそれからだ
kiakiraki
1
230
自動化したのに回らない テスト運用の壁―AI時代の品質責任と生産性
mfunaki
0
550
FastAPI の並行処理モデルを完全に理解する
hoto17296
9
3.3k
仕様駆動開発の消費期限
watany
20
9.1k
夏だ!祭りだ!祭りとはドメインモデリングでは?
ryugen04
0
460
Featured
See All Featured
Context Engineering - Making Every Token Count
addyosmani
9
1.1k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
630
Darren the Foodie - Storyboard
khoart
PRO
3
3.8k
Are puppies a ranking factor?
jonoalderson
2
3.8k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
6
1.2k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.4k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.5k
ラッコキーワード サービス紹介資料
rakko
1
4.6M
A Tale of Four Properties
chriscoyier
163
24k
HDC tutorial
michielstock
2
830
Why Our Code Smells
bkeepers
PRO
340
58k
Transcript
OpenAPIからのRustクライアントコード生成 2024-07-24 Rust、何もわからない…#13 @matsu7874 #Rust何もわからない
matsu7874 株式会社estieでソフトウェアエンジニアをしています。 RustでWebアプリケーションを開発しています。 自己紹介 © 2024 estie, Inc. 1
OpenAPI Generatorを使おう これで必要なブロックが揃います。 npm install @openapitools/openapi-generator-cli -g openapi-generator-cli generate -i
api.yaml -g rust -o generated-client 結論 © 2024 estie, Inc. 2
1. 今回は使う側の話 2. OpenAPI周りのツール群 3. OpenAPI Generator 目次 © 2024
estie, Inc. 3
1. 今回は使う側の話
schema first VS code first の話ではない Rustでバックエンドを書く部分では code first なcrateを使っている async_graphql
paperclip 1. 今回は使う側の話 © 2024 estie, Inc. 5
他の言語で開発されたAPIをRustから使いたい 基盤チームが開発してくれているAPIをプロダクトから使いたい OpenAPI 3.1.0形式でAPI仕様を共有している 今後も基盤の開発が続きそうで、API仕様が変わるかもしれない 1. 今回は使う側の話 © 2024 estie,
Inc. 6
2. OpenAPI周りのツール群
今回の用途に適したものがない utoipa Rust->OpenAPIの変換ツール paperclip OpenAPI 3.1.0形式に対応していない Progenitor OpenAPI 3.1.0形式に対応していない Swagger
Codegen jarファイルが必要?未検証 2. OpenAPI周りのツール群 © 2024 estie, Inc. 8
3. OpenAPI Generator
Webエンジニアにとってインストールが簡単 npm install @openapitools/openapi-generator-cli -g 3. OpenAPI Generator © 2024
estie, Inc. 10
コード生成も簡単 openapi-generator-cli generate -i api.yaml -g rust -o generated-client 3.
OpenAPI Generator © 2024 estie, Inc. 11
生成されたファイル群 generated-client ├── Cargo.toml ├── README.md ├── docs │ └──
モデルに対応するドキュメント.md ├── git_push.sh └── src ├── apis │ ├── configuration.rs │ ├── default_api.rs │ └── mod.rs ├── lib.rs └── models ├── mod.rs └── モデルごとの.rs 3. OpenAPI Generator © 2024 estie, Inc. 12
生成されたコードの使い方 use chat::{apis, models}; #[tokio::main] async fn main() { let
mut config = apis::configuration::Configuration::new(); let request = models::Chat::new(vec![ models::ChatRequestMessagesInner::ChatMessageParam(Box::new( "接続成功してくれ!!!!!!!".to_string(), )), ]); let result = apis::default_api::chat_api_post( &config, request, ).await; } 3. OpenAPI Generator © 2024 estie, Inc. 13
OpenAPI Generatorの弱点 Rust向けに対応していない項目もある anyOf 未対応 oneOf は対応済み https://openapi-generator.tech/docs/generators/rust/ 3. OpenAPI
Generator © 2024 estie, Inc. 14
まとめ
OpenAPI Generatorを使おう RustでOpenAPIを使う際にはOpenAPI Generatorを使うのが簡単 一部対応していない項目はあるが 生成されたコードを使ってAPI呼び出し部分を実装しよう まとめ © 2024 estie,
Inc. 16