Supabase API 명세서 yaml과 html, pdf 로 변환하기

Sungyong
4 min readSep 3, 2024

--

BaaS(Backend as a Service)로 supabase를 사용한다. 오픈 소스인데다가, 기능도 좋다. 처음 Firebase 대체제로 나왔는데, 지금은 Firebase를 오히려 능가하지 않나라는 생각마저 든다.

DB에 대한 API를 pgREST를 사용하고 있고, 명세서 자체를 Web Console에서 보고 테스트도 가능하다.

DB를 table 단위로 직접 접근하는 것은 제품 단계에서는 피해야하지만, PoC 단계에서는 가장 생산성 좋은 방법이다.

Admin Console 공유하지 않고, 외부에 API 명세서만 공유를 할 필요가 있을 때는 swagger 형식의 yaml 이나 pdf 로 전달해 줘야 한다.

그 과정을 정리해 본다.

먼저 swagger format json을 다운 받기.

https://<your unique hostname>.supabase.co/rest/v1/?apikey=<api key>
결과

JSON 형식으로 swagger API 문서가 받아진다.

이걸 VSCode에 넣고, OpenAPI Preview로 보면 이렇게 잘 나오는 것을 볼 수 있다.

OpenAPI Preview

OpenAPI 에서 바로 pdf 변환하는 방법은 없다.

html 로 변환해서 pdf 로 출력하는 방식을 택해야 한다.

yaml을 html 로 변환하는 툴은 redoc-cli를 사용했다.


make yaml2html
cd doc/iot-platform && make yaml2html
make[1]: Entering directory '/home/sungyong/workspace/doc/iot-platform'
Converting YAML to HTML
redoc-cli bundle specifications/rest-api-db.yaml --output specifications/rest-api-db.html --title "My Platform REST API"

┌───────────────────── DEPRECATED ─────────────────────┐
│ │
│ This package is deprecated. │
│ │
│ Use `npx @redocly/cli build-docs <api>` instead. │
│ │
└──────────────────────────────────────────────────────┘

[ReDoc Compatibility mode]: Converting OpenAPI 2.0 to OpenAPI 3.0
Prerendering docs

🎉 bundled successfully in: specifications/rest-api-db.html (1881 KiB) [⏱ 2.624s]
make[1]: Leaving directory '/home/sungyong/workspace/doc/iot-platform'

이렇게 해서 html 파일로 변환된 것을 web browser로 연다.

그 다음 browser에서 pdf 로 print를 통해 파일로 저장하면 완료.

--

--