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
780
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
490
社外を巻き込んだ勉強会を定期開催するコツ
matsu7874
0
240
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
Claude CodeとAgentCore Gatewayを繋ぐ際の認証認可 / Authentication and authorization when connecting Claude Code with AgentCore Gateway
har1101
2
260
Welcome to the "Parametricity" 🏙️ − Generic だけど Specific な世界 −
guvalif
PRO
1
200
JAWS-UG横浜 #102 AWSサ終供養LT会 成仏できない AWS サービスたち 〜本日、三体供養します〜
maroon1st
0
340
メールのエイリアス機能を履き違えない
isshinfunada
0
230
型も通る、synthも通る、それでも危ない 〜AIのCDKの権限とコストを機械で検証する〜 / It Passes Type Checks, It Passes Synth Checks, but It’s Still Risky — Automatically Verifying Permissions and Costs in AI’s CDK —
seike460
PRO
1
540
「寝てても仕事が進む」Claude Codeで組む第二の脳
tomoyafujita2016
0
310
関東Kaggler会_NVIDIA_Nemotron_コンペ_振り返り
rick_ds
0
490
20260722_microCMSで考える、AI時代のコンテンツ運用設計
yosh1
0
380
【やさしく解説 設計編・中級 #6】良いアーキテクチャとは ~ 一本の登り道の、行き先 ~
panda728
PRO
0
210
AI Engineeringは、AIプロダクトだけのものか? 〜AIがソフトウェアを作る時代の新しい当たり前〜 / No AI in your product. AI Engineering in your development.
rkaga
4
380
Japan Community Day at Kubecon + CloudNativeCon Japan 2026: Learning Container Privilege Control by Building My Own Low-Level Container Runtime
ternbusty
1
150
Claude Code全社展開のためにやったことn選~プラグイン302個・コミッター271人を支えるために~
kenchan
5
1.4k
Featured
See All Featured
Become a Pro
speakerdeck
PRO
31
6.2k
Designing for Performance
lara
611
70k
Darren the Foodie - Storyboard
khoart
PRO
3
3.6k
Code Review Best Practice
trishagee
74
20k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
210
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Building the Perfect Custom Keyboard
takai
2
830
A Guide to Academic Writing Using Generative AI - A Workshop
ks91
PRO
1
360
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Are puppies a ranking factor?
jonoalderson
1
3.8k
The Impact of AI in SEO - AI Overviews June 2024 Edition
aleyda
5
1.2k
Music & Morning Musume
bryan
47
7.3k
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