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
ASP.NET Core の OpenAPIサポート
Search
Toshimasa Hashiguchi
January 14, 2025
Programming
0
260
ASP.NET Core の OpenAPIサポート
.NET Conf 2024 Fukuoka x Osaka にてお話させていただいた内容になります。
https://fukuten.connpass.com/event/333954/
Toshimasa Hashiguchi
January 14, 2025
Tweet
Share
More Decks by Toshimasa Hashiguchi
See All by Toshimasa Hashiguchi
PostmanでAPIの動作確認が楽になった話
h455h1
0
580
Other Decks in Programming
See All in Programming
型付きアクターモデルがもたらす分散シミュレーションの未来
piyo7
0
810
プロダクト志向ってなんなんだろうね
righttouch
PRO
0
160
生成AIコーディングとの向き合い方、AIと共創するという考え方 / How to deal with generative AI coding and the concept of co-creating with AI
seike460
PRO
1
330
GoのGenericsによるslice操作との付き合い方
syumai
3
690
ruby.wasmで多人数リアルタイム通信ゲームを作ろう
lnit
2
270
VS Code Update for GitHub Copilot
74th
1
390
Beyond Portability: Live Migration for Evolving WebAssembly Workloads
chikuwait
0
390
Team topologies and the microservice architecture: a synergistic relationship
cer
PRO
0
1k
プロダクト志向なエンジニアがもう一歩先の価値を目指すために意識したこと
nealle
0
110
Kotlin エンジニアへ送る:Swift 案件に参加させられる日に備えて~似てるけど色々違う Swift の仕様 / from Kotlin to Swift
lovee
1
260
生成AIで日々のエラー調査を進めたい
yuyaabo
0
650
今ならAmazon ECSのサービス間通信をどう選ぶか / Selection of ECS Interservice Communication 2025
tkikuc
19
3.6k
Featured
See All Featured
Designing Experiences People Love
moore
142
24k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.1k
Statistics for Hackers
jakevdp
799
220k
Practical Orchestrator
shlominoach
188
11k
Scaling GitHub
holman
459
140k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
667
120k
A Tale of Four Properties
chriscoyier
160
23k
Building Adaptive Systems
keathley
43
2.6k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
252
21k
Art, The Web, and Tiny UX
lynnandtonic
299
21k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
20
1.3k
Mobile First: as difficult as doing things right
swwweet
223
9.7k
Transcript
ASP.NET Core の OpenAPIサポート 2025/1/11 .NET Conf 2024 Fukuoka x
Osaka
None
Toshimasa Hashiguchi Alterbooth.inc Webアプリケーション開発 Technology: C#、.NET、Azure、GitHub、XR Community: Fukuoka.NET、福岡XR部 X:@h455h1
OpenAPIの概要 - HTTP API の定義に使用される標準的なフォーマット - API のエンドポイント、リクエスト、レスポンスなどの情報を一貫して記述可能 - 機械にも人間にも優しい
- さまざまな開発者やAPIベンダー、ツールがOpenAPIを使用して連携可能
ASP.NET Core 9.0のOpenAPIサポート - ASP.NET Coreでは、OpenAPIのサポートが組み込まれている - ASP.NET Coreアプリでは、Microsoft.AspNetCore.OpenApiパッケージを使用し て、アプリ内のエンドポイントに関する情報を生成
- 生成されたOpenAPIドキュメントは、エンドポイントまたはシリアル化されたファイル を通して公開
ASP.NET Core 9.0 Web API テンプレート(MinimalAPI) エンドポイントを アプリケーションに追加 DIコンテナーに登録 Microsoft.AspNetCore.OpenApiパッ
ケージを介して提供
ASP.NET Core 9.0 Web API テンプレート(MinimalAPI) エンドポイントを アプリケーションに追加 DIコンテナーに登録 /openapi/v1.json
ASP.NET Core 9.0 Web API テンプレート(MinimalAPI) エンドポイントを アプリケーションに追加 DIコンテナーに登録
ASP.NET Core 8.0 Web API テンプレート との比較 Swaggerジェネレータを サービスコレクションに追加 APIドキュメントと
Swagger UI を提 供するミドルウェアを有効化
なぜSwagger(Swashbuckle )取り除かれたのか? Swaggerジェネレータを サービスコレクションに追加 APIドキュメントと Swagger UI を提 供するミドルウェアを有効化 https://dev.to/eminvergil/an-alternative-to-swagger-in-dotnet-9-2jd6
1. メンテナンスの問題 2. ASP.NET Coreの進化 3. OpenAPIへのフォーカス 4. 代替ツールの提供 5. コミュニティ主導のイノベーションの促進
Swagger(Swashbuckle)を使用する https://learn.microsoft.com/ja-jp/aspnet/core/fundamentals/openapi/using-openapi-documents?view =aspnetcore-9.0&WT.mc_id=%3Fwt.mc_id%3DDT-MVP-5004827#use-swagger-ui-for-local-ad-hoc -testing
ASP.NET Core アプリに OpenAPI メタデータを含める Minimal API Controller Base WebAPI
ビルド時に OpenAPI ドキュメントを生成する - Microsoft.Extensions.ApiDescription.Serverパッケージをインストール - プロジェクトファイルで出力されるAPIドキュメントの場所を指定 - dotnet build
ビルド時に OpenAPI ドキュメントを生成する
CIパイプラインでごにょごにょできるってコト?
GitHub Actionsを使用してWikiのAPIドキュメントを自動更新する APIの更新 ビルド Wiki Push OpenAPI Document Markdown GitHub
Actions
GitHub Actionsを使用してWikiのAPIドキュメントを自動更新する widdershins - OpenAPI仕様からMarkdownへの変換 - https://github.com/Mermade/widdershins
GitHub Actionsを使用してWikiのAPIドキュメントを自動更新する https://github.com/t0ottio13/sample-openapi-document-sync/actions
Demo
まとめ - ASP.NET Coreでは、Microsoft.AspNetCore.OpenApiパッケージと Microsoft.Extensions.ApiDescription.Serverパッケージを使用して、OpenAPIド キュメントの生成がサポートされている - ASP.NET Core Web
API テンプレートからSwashbuckleが削除された - CIパイプラインと組み合わせるとAPIドキュメントの自動生成ができる
おまけ1:.httpファイル https://youtu.be/uKm1ho881gk?si=wsEPfTLOzlitHOI2
おまけ:.httpファイル https://youtu.be/uKm1ho881gk?si=wsEPfTLOzlitHOI2 @name を使用するとリクエスト結果を変数に格納できる
おまけ:.httpファイル @nameで定義した変数へのアクセス方法 The expression should adhere to the following pattern:
{{requestName.(response|request).(body|headers).(*|JSONPath|XPath|Header Name)}}. https://youtu.be/uKm1ho881gk?si=wsEPfTLOzlitHOI2
ご清聴ありがとうございました。
References - https://learn.microsoft.com/ja-jp/aspnet/core/release-notes/aspnetcore-9.0?vie w=aspnetcore-9.0#openapi - https://learn.microsoft.com/ja-jp/aspnet/core/tutorials/getting-started-with-swa shbuckle?view=aspnetcore-7.0&tabs=visual-studio - https://devblogs.microsoft.com/dotnet/dotnet9-openapi/ -
https://dev.to/eminvergil/an-alternative-to-swagger-in-dotnet-9-2jd6 - https://youtu.be/ooP0vkST3X8?si=vuotRdxOGkMx5X4T - https://learn.microsoft.com/ja-jp/aspnet/core/fundamentals/openapi/using-ope napi-documents?view=aspnetcore-9.0&WT.mc_id=%3Fwt.mc_id%3DDT-MV P-5004827#use-swagger-ui-for-local-ad-hoc-testing