058 | Asciidocs, Asciidoctor
๐ Asciidoc
Asciidoc์ Spring Rest Docs๋ฅผ ํตํด ์์ฑ๋๋ ํ ์คํธ ๊ธฐ๋ฐ ๋ฌธ์๋ก, ๊ธฐ์ ๋ฌธ์ ์์ฑ์ ์ํด ์ค๊ณ๋ ๋งํฌ๋ค์ด ์ธ์ด์ด๋ค.
๐งฉ ๋ชฉ์ฐจ
= ๋ฌธ์ ์ ๋ชฉ
:sectnum:
:toc: left
:toclevels: 1~6
:toc-title: ํ์ดํ
:source-highlighter: prettify
- = ๋ฌธ์ ์ ๋ชฉ: Ascii ๋ฌธ๋ฒ์ผ๋ก ๋ชฉ์ฐจ๋ฅผ ๊ตฌ์ฑํ๋ค.
- :sectnum:: ๊ฐ ์น์ ์ ๋๋ฒ๋ง์ ํ๋ค.
- :toc: left: ๋ฌธ์์ ๋ชฉ์ฐจ๋ฅผ ์ด๋์ ๊ตฌ์ฑํ ๊ฒ์ธ์ง ์ ํ๋ค. left๋ ๋ชฉ์ฐจ๋ฅผ ์ผ์ชฝ์ผ๋ก ํ๋ค.
- :toclevels: 3: ๋ชฉ์ฐจ์ ํ์ํ ๊ฐ ์น์ ์ ์ ๋ชฉ์ level(HTML๊ธฐ์ค h1~h6)์ ์ ํ๋ค. 3์ผ๋ก ์ง์ ํ ์ === ๊น์ง์ ์ ๋ชฉ์ ๋ชฉ์ฐจ์ ํฌํจ์ํจ๋ค.
- :toc-title: ํ์ดํ: ๋ชฉ์ฐจ์ ์ ๋ชฉ์ ์ง์ ํ ์ ์๋ค.
- source-highlighter: prettify: ์์ค์ฝ๋ ํ์ด๋ผ์ดํธ๋ฅผ ์ง์ ํ๋ค.
๐งฉ ๋ฐ์ค ๋ฌธ๋จ
***
๋ฌธ๋จ ์ ๋ชฉ
๋ฌธ๋จ์ ๋ด์ฉ์ด๋ค. Spring MVC ๊ธฐ๋ฐ์ REST API ๊ธฐ๋ฐ ์ ํ๋ฆฌ์ผ์ด์
์ ๊ณต๋ถํ๊ณ ์๋ค.
CAUTION: ๊ฒฝ๊ณ ๋ฌธ๊ตฌ ๊ธฐ์ฌ
***
- ***: ๋จ๋ฝ์ ๊ตฌ๋ถ์ง๋ ์ํ์ ์ ์ถ๊ฐํด์ค๋ค.
- : ๋ฌธ๋จ ์ ๋ชฉ ๋ค์ ํ ์ค ๋์ฐ๊ณ ํ ์นธ ๋ค์ฌ์ฐ๊ธฐ๋ฅผ ํ๋ฉด ๋ฐ์ค ๋ฌธ๋จ์ ์ฌ์ฉํ ์ ์๋ค.
- CAUTION: ๊ฒฝ๊ณ ๋ฌธ๊ตฌ๋ฅผ ์ถ๊ฐํ ์ ์๋ค. NOTE:, TIP:, IMPORTANT:, WARNING: ๋ฑ์ ์ฌ์ฉํ ์ ์๋ค.
๐ Asciidoctor
Spring Rest Docs์์ Asciidoc ํฌ๋งท์ ๋ฌธ์๋ฅผ ํ์ฑํด์ HTML 5, ๋งค๋ด์ผ ํ์ด์ง, PDF ๋ฐ EPUB 3 ๋ฑ์ ํ์ผ๋ก ๋ณํํ ๋ฌธ์๋ฅผ ์์ฑํ๋ ํด์ด๋ค.
๐งฉ ๋ฌธ์ ์ค๋ํ
Spring Rest Docs ํ ์คํธ์ผ์ด์ค๋ฅผ ์ ๋ถ ํต๊ณผํ๋ฉด build/generated-snippets/idenntifier ๋๋ ํ ๋ฆฌ์ .adoc ์ค๋ํ ๋ฌธ์๊ฐ ์์ฑ๋๋ค.
Gradle์์ task > build๋ฅผ ์คํํ๋ฉด Asciidoctor๊ฐ ๊ฐ๊ฐ์ ์คํผ๋ ๋ฌธ์๋ค์ ๋ชจ์ index.adoc → index.html, ํ๋์ html ํ์ผ๋ก ๋ณํ ํ ํน์ ๋๋ ํ ๋ฆฌ(src/main/resources/static/docs)์ ์ ์ฅํด์ค๋ค.
- index.adoc์ ์คํผ๋ ํฌํจํ๊ธฐ
.snippet1
include::{snippets}/identifier/snippet1.adoc[]
.snippet2
include::{snippets}/identifier/snippet2.adoc[]
- .snippet: ์ค๋ํ ์ ๋ชฉ ํํ
- include::{snippets}/identifier/snippet.adoc[]
- include: Asciidoctor์์ ์ฌ์ฉํ๋ ๋งคํฌ๋ก๋ก, ์ค๋ํ์ ๋ฌธ์์ ํฌํจํ ๋ ์ฌ์ฉํ๋ค.
- ::: ๋งคํฌ๋ก๋ฅผ ์ฌ์ฉํ๋ค.
- {snippets}: ํด๋น ์ค๋ํ์ด ์์ฑ๋๋ ๋ํดํธ ๊ฒฝ๋ก์ด๋ฉฐ build.gradle์ ์ค์ ํ snippersDir ๋ณ์๋ฅผ ์ฐธ์กฐํ๋๋ฐ ์ฌ์ฉํ ์ ์๋ค.
โ Ref.
https://docs.spring.io/spring-restdocs/docs/current/reference/html5/#working-with-asciidoctor
Spring REST Docs
Document RESTful services by combining hand-written documentation with auto-generated snippets produced with Spring MVC Test, WebTestClient, or REST Assured.
docs.spring.io
https://docs.asciidoctor.org/asciidoc/latest/toc/
AsciiDoc - Automatic Table of Contents
A documentation page for AsciiDoc.
docs.asciidoctor.org