Redoc์ ํตํ ๋ถ์ฐ ์๋น์ค ํตํฉ API ๋ฌธ์ ๋ฐฐํฌ ๋์ ๊ธฐ
๋๋ ์๋ ์ฌ์ฉํ๋ ์๋ฒ์ API ๋ช ์ธ์๋ ํญ์ springdoc ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ด์ฉํ์ฌ Swagger๋ฅผ ๋ง๋ค์์๋ค.
๋ถ์ฐ ์๋น์ค ํ๊ฒฝ์์ Swagger๋ฅผ ์ด์ฉํ๋ค๋ฉด, ๋ค์๊ณผ ๊ฐ์ด ์๋น์ค ๋น URL์ด ์๊ฒจ ํ์ํ ๋ช ์ธ์๋ฅผ ์ฐพ์ ๋งํฌ๋ฅผ ์ด๋ฆฌ์ ๋ฆฌ ์ฎ๊ฒจ๋ค๋ ์ผ ํ๋ ์ํฉ์ด ์๊ธด๋ค.
์ด๋ฌํ ๋ฌธ์ ๋ฅผ ์ธ์งํ๊ณ ์๋ค๊ฐ, ์ด ์ข๊ฒ ๋ผ์ธ ํ ํฌ ๋ธ๋ก๊ทธ์ ๊ธ์ ๋ณด์๋ค!
https://techblog.lycorp.co.jp/ko/api-document-integration-and-documentation-automation
๋ชจ๋๊ฐ ํ๋ณตํด์ง๋ API ๋ฌธ์ ํตํฉ๊ณผ ์๋ํ
๋ค์ด๊ฐ๋ฉฐ ์๋ ํ์ธ์. LINE Plus์์ LINE Monary์ MyDashboard ์๋น์ค์ ๋ฐฑ์๋๋ฅผ ๋งก๊ณ ์๋ ์กฐ์ฑ๋น์ ๋๋ค. ์ด๋ฒ ๊ธ์์๋ ๋ฐฑ์๋ ์๋น์ค ๊ฐ๋ฐ ๋ฐ ์ด์ ์ ๋ฌด๋ฅผ...
techblog.lycorp.co.jp
๋ฐ๋ก ํ๋ก์ ํธ์ ์ ์ฉํด ๋ณด์์ผ๊ฒ ๋ค๊ณ ์๊ฐํ๋ค.
Github Pages
ํตํฉ๋ ๋ฌธ์์ ๋ํ ํ์ด์ง๋ Github Pages๋ฅผ ์ด์ฉํ์ฌ ๋ฐฐํฌ๋๋ค.
Github Pages๋ ๊นํ๋ธ ๋ ํฌ์ ์ ์ ์ธ ์น์ฌ์ดํธ ์ด๋ฏธ์ง๋ฅผ ์์ฝ๊ฒ ๋ฐฐํฌํด์ฃผ๋ ๊ธฐ๋ฅ์ด๋ค.
์ฌ๋ฌ ๋ธ๋ก๊ทธ์์ ๋ดค๋ ๋๋ฉ์ธ ํ์์ธ ~~~.github.io ํ์์ด๋ค.
Redoc
๋ฌธ์ ํ์ด์ง ์์ฑ์ Redoc์ด๋ผ๋ ๋๊ตฌ๋ฅผ ์ฌ์ฉํ๋ค.
๋๋ ํ์ Swagger๋ง ์ ํด๋ณด์์๋๋ฐ, Redoc์ ๊ฒฝํํ๋ ์ข์ ๊ธฐํ๋ก ์ผ๊ณ ๋์ ํด๋ณด๊ธฐ๋ก ํ๋ค !!
https://redocly.github.io/redoc/
ReDoc Interactive Demo
ReDoc Interactive Demo. OpenAPI/Swagger-generated API Reference Documentation
redocly.github.io
Redoc ๋ช ์ธ์์ ๋ฐ๋ชจ ์ฌ์ดํธ์ด๋ค.
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.3'
id 'io.spring.dependency-management' version '1.1.4'
id "org.springdoc.openapi-gradle-plugin" version '1.8.0'
}
//...
dependencies {
//Springdoc
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0'
}
gradle-plugin์ ์์กด์ฑ์ ์ถ๊ฐํด๋๋ฉด gradle task๋ฅผ ํตํด API ๋ฌธ์๋ฅผ JSON ํํ๋ก ์ถ์ถํ ์ ์๋ค.
์ด๋ฅผ ์ํ ๋ช๊ฐ์ง build.gradle ์ค์ ์ ๋ด ์๋ฒ์ ๋ง๊ฒ ์ ์ฉํด ๋ณด์๋ค.
openApi {
apiDocsUrl.set("http://localhost:8000") // Document URL
outputDir.set(file("$rootDir/docs")) // Build Result Path
outputFileName.set("noti.json") // Build Result File Name
groupedApiMappings.set(Map.of("http://localhost:8082/noti/api-docs", "noti.json"))
waitTimeInSeconds.set(60) // Timeout
customBootRun {
args.add("--spring.profiles.active=dev")
}
}
๋ณธ๋ฌธ์ $buildDir ์ Deprecate ๋์๋ค๊ณ ํ๋ค. $rootDir ๋ก ๋ฐ๊ฟ์ฃผ์๋ค.
์คํ
gradle์ generateApiDocs Task๋ฅผ ์คํํ๋ฉด ์ ํ๋ฆฌ์ผ์ด์ ์ ํ ๋ฒ ์คํํ๊ฒ ๋๋ค.
openapi๋ฅผ ํตํด ๋ง๋ค์ด์ง API ๋ช ์ธ์๋ฅผ ์ถ์ถํด์ผ ํ๊ธฐ ๋๋ฌธ์ด๋ค.
๊ทธ๋ ๋ค๋ฉด, ์๋ ๊ฐ์ด ๋ง๋ฌผ๋ ค์ ๋์๊ฐ Spring Cloud Config , Eureka , Kakfa ... ๊ฐ ์ผ์ ธ์์ด์ผ ๋๋ค๋ ๊ฒ์ด๋ค.
1ํ์ฑ ์คํ์ด๊ธฐ ๋๋ฌธ์ Eureka, Kafka๋ ํ์์๊ฒ ์ง๋ง.. Config Server๊ฐ ์์ผ๋ฉด ๊ตฌ๋์ด ์๋๋ค.
GitHub Action Runner๋ ๊ฐ์ํ๊ฒฝ์ด๊ธฐ ๋๋ฌธ์, ์ด๋ฅผ ํด๊ฒฐํ๋ ค๋ฉด ๊ฐ์ํ๊ฒฝ์์ ๊ตฌ๋ํด์ผ ํ๋ค.
๊ฒฐ๊ณผ๋ yml์ด ์์ผ๋ ์คํจ ..
์ด๋ฐ ์ชฝ ์ง์์ด ์๋ ๋๋ ํผ๋์ ๋น ์ก๋ค..
1. 1ํ์ฑ ์คํ์ด๋๊น DataSource ๋ฅผ Excludeํ๊ณ ์คํ
์ง์ mainํจ์์์ datasourceConfiguration์ excludeํ๋ ๋ฐฉ๋ฒ. ๋์๋ ์ ์๊ฒ ์ง๋ง, ์ข์ ๋ฐฉ๋ฒ์ด ์๋๋ผ๊ณ ์๊ฐ
2. 1ํ์ฑ application.yml์ ์ฃผ์
Github Action Secret์ ํตํด ์ค์ ๊ฐ์ ์ฃผ์ ํ๊ณ RDS์ ์ฐ๊ฒฐํ๋ ๋ฐฉ๋ฒ. RDS๋ฐฐํฌ ์ํ๊ฐ ์๋๋ผ๋ฉด ์คํํ ์ ์์
3. Spring Cloud Config๋ง ๋ฏธ๋ฆฌ ๋ฐฐํฌํด๋๊ณ Fetching
Config Server๋ฐฐํฌ ์ ์ํ. ๋ณ์๊ฐ ๋ง์์ง๊ณ ์ค๋ฒํค๋๊ฐ ํผ. ๋ํ, ์ด๋ฏธ ๋ฐฐํฌํ ์ํ๋ผ๋ฉด ๋ฐฐํฌ๋ ์ ํ๋ฆฌ์ผ์ด์ ๊ณผ ์ค๋ณต ์ ๊ทผ์ด ์ผ์ด๋ ์ ์์
4. Github Runner์ Config Service๋ฅผ ๊ฐ์ ธ์์
yml ์ ์ฅ์์ ํต์ ํ private key๋ํ ์ถ๊ฐ๋ก ์ค์ ์ด ํ์ํจ. ํ๋ก์ธ์ค ๋ํ ๊ธธ์ด์ง๊ณ , ์ค๋ฒํค๋๊ฐ ํผ
๊ฒฐ๊ตญ ๊ทธ๋๋ง 2๋ฒ์ ์ ํํด Github Action Secret์ ์ด์ฉํ์ฌ 1ํ์ฑ bootstrap.yml ์ ์ฃผ์ ํด๋ณด๊ธฐ๋ก ๊ฒฐ์ ํ๋ค.
60์ด Timeout ์ ๊ฑธ์ด๋จ๋ ๊ฒ์์ ๊ฑธ๋ ธ๋ค. 60์ด๋ฅผ ๊ธฐ๋ค๋ ค๋ ๋ฐ์ง ๋ชปํ ๊ฒ์ด๋ค.
Kafka ์๋ฒ์ ํ ํฝ ์์ฑ, ๊ตฌ๋ , Eureka ์๋ฒ ๋ฑ๋ก ์๋ ๋ฑ๋ฑ ์๋ฒ ๊ตฌ์ถ์ ๋๋ฌด ์ค๋ ์๊ฐ์ด ๊ฑธ๋ฆฐ๋ค.
๋ฌผ๋ก timeout์ ๊ธธ๊ฒ ์ค์ ํ๋ฉด ๋๊ฒ ์ง๋ง,
API ๋ช ์ธ์๋ฅผ ์ํด ์๋ฒ๋ฅผ ๋น๋ํ๊ณ ์ถ์ถํ๋ ๊ณผ์ ์ ๋๋ฌด ๋ฌด๊ฒ๋ค๊ณ ์๊ฐํ๋ค.
๊ทธ๋์ ๋ฐฉ๋ฒ์ ์กฐ๊ธ ๋ฐ๊พธ๊ธฐ๋ก ํ๋ค.
ํ์
gradle task๋ฅผ ํตํด ์ถ์ถ๋ json ์ Github Action์ด ๊ฐ์ ธ๊ฐ์ ์์ฑํ๊ธฐ๋ก ํ๋ค.
API ์คํ์ด ๋ฐ๋๋ฉด task๋ฅผ ๋ก์ปฌ๋ก ์คํํ๊ธฐ๋ก ํ๋ค. API ์คํ์ ๊ทธ๋ ๊ฒ ๋ง์ด ๋ฐ๋์ง ์์ผ๋..
์ผ๋จ Github Pages๋ฅผ ๋ฐฐํฌํ ๋ ํฌ๋ฅผ ๋ง๋ค์๋ค.
<owner ์ด๋ฆ>.github.io ์ด๋ฆ์ผ๋ก ๋ง๋ค์ด์ผ ํ๋ค.
$ ssh-keygen -t rsa -b 4096 -C "{email}"
ssh ํค๋ฅผ ๋ง๋ค์ด์ค๋ค.
์ฌ๊ธฐ์ ์ค์ํ ์ ์, Deploy Key๋ก ์ฌ์ฉํ๋ ค๋ฉด passphrase๋ฅผ ์ค์ ํ์ง ์๋๊ฒ์ด ์ข๋ค.
ssh-agent๋ฅผ ๋ง๋ webfactory์์ '์ด์ฐจํผ private key๋ Secret์ ์ ์ฅ๋๋ ์์ ํ ๊ฒ์ด๊ณ , passphrase๋ฅผ Input์ผ๋ก ๋ฃ์ง ์์๋ ์คํ๋์ด์ผ ํ๊ธฐ ๋๋ฌธ์ด๋ค.' ๋ผ๊ณ ํ๋ค.
์ค์ ๋ก passphrase๊ฐ ์๋ ํค๋ฅผ ๋ฃ์ผ๋ฉด input์ ์๊ตฌํ๊ณ , ์๋ค๋ฉด Action์ด ์คํจํ๋ค.
๋ ํฌ์ public key๋ฅผ Deploy Key๋ก ๋ฑ๋กํด์ค๋ค.
์ด์ ๋ณธ ๋ ํฌ์ github action ์คํฌ๋ฆฝํธ๋ฅผ ์์ฑํ๋ค.
name: API Docs Integration
on:
push:
branches:
- develop
jobs:
api-docs-integration:
runs-on: ubuntu-latest
steps:
# ํ๋ก์ ํธ ์ฝ๋ ๊ฐ์ ธ์ค๊ธฐ
- name: Checkout Code
uses: actions/checkout@v3
with:
ref: 'develop'
# Json ํ์ผ ๊ฐ์ ธ์ค๊ธฐ
- name : collect json
run : |
cp ./noti-service/docs/noti.json ./
cp ./user-service/docs/user.json ./
cp ./weather-service/docs/weather.json ./
# [Redoc] json ํ์ผ join
- name: redoc-cli join
uses: DeltaLaboratory/redocly-cli-action@v1.0.0
with:
args: 'join *.json -o api.yaml'
- name: check result
run: |
ls -al
test -f api.yaml || (echo "Missing api.yaml from previous step." && exit 1)
# [Redoc] Build docs
- name: redoc-cli build docs
uses: DeltaLaboratory/redocly-cli-action@v1.0.0
with:
args: 'build-docs api.yaml -o index.html'
- name: check result
run: |
ls -al
test -f index.html || (echo "Missing index.html from previous step." && exit 1)
# ์นํ์ด์ง Repository์ Push
- name: Install SSH Key
uses: leigholiver/commit-with-deploy-key@v1.0.4
with:
source: index.html
destination_folder: docs
destination_repo: WaitherTeam/WaitherTeam.github.io
destination_branch: main
deploy_key: ${{ secrets.DEPLOY_KEY }}
Redoc-cli
์ฒ์์๋ Marketplace์ star๊ฐ ๊ฐ์ฅ ๋ง์ ์์ ์๋๊ฑธ ์ด์ฉํ๋๋ฐ,
๊ณ์ ์คํจ๋ฅผ ๊ฑฐ๋ญํ๋ค.
์คํฌ๋ฆฝํธ๋ฅผ ์๋ชป ์ผ๋์ง, args๋ฅผ ์ ๋ชป ์ ๋ฌํ๋์ง ๊ณ์ํด์ ํ์ธํ๊ณ ์์ ํ๊ณ ๋ฅผ ๋ฐ๋ณตํ๋ค.
์ง์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ๋ฏ์ด๋ณด๋ ๋์ปค ์ด๋ฏธ์ง๋ฅผ ๊ฐ์ ธ์์ redoc-cli๋ฅผ arg๋ฅผ ์ ๋ฌํ์ฌ ์คํํ๋ ๋ฏ ํ๋ค.
๋์ปค ๋ด์์ ์๋ํ๋ค ๋ณด๋ ๋ก๊ทธ๋ ๋ณด์ด์ง ์๊ณ ๋ต๋ตํ๋ค ๐ซ
https://redocly.com/docs/cli/commands/join/
join
OpenAPI-generated documentation tool with 17,000+ stars on Github - for API docs you can be proud of.
redocly.com
์ง์ Redoc ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ฐพ์๊ฐ์ join ๋ช ๋ น์ด๋ฅผ ๋ณด์๋๋ฐ, join์ด ์คํ์ ๊ธฐ๋ฅ...?
๊ทธ๋๋ ๋ก์ปฌ์์ ์ง์ ์คํํด๋ณด๋, ์๋ํ์ง ์๋ ๊ฒ์ด ์๋๋ค.
์ฌ๊ธฐ์ ๋ ผ๋ฆฌ์ ์ถ๋ก ์ผ๋ก.. join์ด ์คํ์ ๊ธฐ๋ฅ์ด๋ผ๋ ๋ป์ ๊ฐ๋ฐ๋์ง ์ผ๋ง ๋์ง ์์๋ค..? ๋ฒ์ ์ด ๋ง์ง ์๋? ๋ผ๋ ์๊ฐ์ด ๋ค์๋ค.
๊ทธ๋์ ์ง์ ๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ปค๋ฐ์ ๋ดค๋๋.. 4๋ ์ ..๐ค ๋ฒ์ ์ด ๋ง์ง ์๋๊ฒ ๋ถ๋ช ํ๋ค.
๊ทธ๋์ ๊ทธ๋๋ง ์ต๊ทผ์ธ DeltaLaboratory/redocly-cli-action@v1.0.0 ์ผ๋ก ๋ฐ๊พธ์๋๋ ๋ฐ๋ก ๋์ํ๋ค.. ๐ฅฒ
[๊ตํ]
1. ๋ก๊ทธ๋ ์ ๋ง ์์คํ๋ค.
2. ๋ฒ์ ํ์ธ๋ ์ ๋ง ์ค์ํ๋ค.
3. ์ ๋ณด๊ฐ ์๋ค๋ฉด ๋ ผ๋ฆฌ์ ์ถ๋ก ๋ฅ๋ ฅ์ ๋ฐํํด๋ผ.
Github Push
๋ผ์ธ ๋ธ๋ก๊ทธ์์ ๊ฐ์ธ Runner๋ฅผ ์ด์ฉํ์ฌ ์ง์ ํ ๋ฏ ํ๋ค.
๊ทธ๋์ ๋๋ ๋ฐ๋ก ๋ ํฌ ์ ๊ทผ ๊ถํ์ ๊ตฌ์ถํด์ผ ํ๋ค.
์ฒ์์๋ deploy key ๋ง๊ณ access token์ผ๋ก ํด๋ณด๋ ค ํ์ง๋ง ์ฌ๊ฐ๋์ ์ด์ ์ด๋ผ ๊ทธ๋ฐ์ง ์ฌ๋ฌ ์ค์ ์ ๋ง์ ธ๋ด๋ 403์ ๋ฐ์ ๋ฟ์ด์๋ค.
๊ฒฐ๊ตญ Deploy Key๋ฅผ ๋ฑ๋กํ๊ณ , Marketplace์์ ๊ฒ์ํด์ ๋ค์์ ์ฌ์ฉํ๋ค.
์ด๋ ๊ฒ ํด๋๊ณ ์นํ์ด์ง ์ค์ ์์ Pages๋ฅผ ํ์ฑํํด์ฃผ๋ฉด ..
๋ฐฐํฌ๊ฐ ์๋ฃ๋๋ค !! ......