Last active
December 5, 2022 13:48
-
-
Save junkor-1011/35f264148d58ad700c3dde739f69e661 to your computer and use it in GitHub Desktop.
LT資料: openapiと同期したWeb API開発(fastify)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>openapi sync WebAPI(fastify)</title> | |
<meta charset="utf-8"> | |
<style> | |
@page { | |
size: 1210px 681px; | |
margin: 0; | |
} | |
@media print { | |
.remark-slide-scaler { | |
width: 100% !important; | |
height: 100% !important; | |
transform: scale(1) !important; | |
top: 0 !important; | |
left: 0 !important; | |
} | |
} | |
body { font-family: sans-serif; } | |
h1, h2, h3 { | |
font-weight: normal; | |
} | |
.remark-code, .remark-inline-code { font-family: 'Ubuntu Mono'; } | |
</style> | |
</head> | |
<body> | |
<textarea id="source"> | |
class: center, middle | |
# Title | |
--- | |
# Agenda | |
1. Introduction | |
2. Deep-dive | |
3. ... | |
--- | |
# Introduction | |
</textarea> | |
<script src="https://remarkjs.com/downloads/remark-latest.min.js"> | |
</script> | |
<script> | |
var slideshow = remark.create({ | |
sourceUrl: 'slides.md', | |
}); | |
</script> | |
</body> | |
</html> |
class: center, middle
- Web APIの実装と、仕様であるOpenAPIを同期させて開発を進められると非常に便利
- 実装、または仕様が先行して乖離が起こる懸念が無くなる
- SwaggerUIはWeb APIのテスト実行用GUIツールとしても便利
- 選択肢が潤沢とまでは言えないので、常に出来るとは限らないのは難点
- 代表的な例としてはPythonのマイクロWebフレームワークであるFastAPIなどがある
- (が、今回はTypeScriptのマイクロWebフレームワークを使いたいので、fastify + fastify-swaggerを使う)
- GitHub
- 軽量でシンプルなマイクロWebフレームワークの部類
- expressなども有名だが、高パフォーマンスだったり、
TypeScriptネイティブだったりする(※expressは
@types/express
が必要)など後発ならではの長所も多い
- DevelopersIO - Fastifyで作るAPIにZodでスキーマバリデーションをかけながら型定義と実用レベルのOpenAPI仕様を自動生成する など
- fastifyはJSON Schemaと連携してバリデーションを行う機能があるが、素のJSON Schemaを書くのを避けるためにfastify-zodを使っている
- fastify-swaggerを使って、OpenAPI仕様を自動出力させている
- fastify-swagger-uiによってswagger-uiの機能を使用でき、GUIからAPIを叩ける
class: center, middle
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment