Hi guys, kali ini gw akan membahas mengenai slate lagi. Beberapa hari belakangan ini gw mencoba cari cara bagaimana membuat dokumentasi yang bagus namun tidak membuat gw repot. Di tiket.com sendiri sebenarnya sudah ada swagger untuk mempermudah developer dalam mengetes api namun balik lagi itu saja sudah tidak cukup. Lalu kepikiran, bisa gak sih ngubah swagger ke slate? At least simplenya gw ga perlu bikin dari awal lagi. Jawabannya adalah bisa tapi ya semi-semi harus update dikit-dikit. Ibarat orang ujian copas tapi butuh config dikit-dikit.
Yang pertama kali dibutuhkan untuk bisa membuat dokumentasi dari swagger adalah ya swagger itu sendiri. Kalau kalian bingung buatnya, bisa pull project github gw disini. Btw disini gw akan menggunakan java untuk projectnya. Sebagai prasyarat untuk menjalankan project gw adalah sebagai berikut :
- JDK 11
- Gradle
- MongoDB (karena kebetulan gw lagi coba main di mongo).
- Intellij IDEA / Eclipse / Netbeans (serius nih hari gini masi pakai netbeans) / notepad++ (sujud sembah ngoding java pakai ini)
Kalau sudah lengkap silahkan jalankan aplikasinya, nanti tampilannya akan seperti ini :

Yang perlu diperhatikan disini adalah url dibawah Service Name yakni http://localhost:7777/v2/api-docs. Langsung klik url tersebut maka akan keluar seperti berikut :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 |
{ "swagger": "2.0", "info": { "description": "API Description", "version": "API", "title": "Service Name", "termsOfService": "Terms of service", "contact": { "name": "Testing Service", "url": "http://immanuelbayu.my.id", "email": "me@immanuelbayu.my.id" }, "license": { "name": "License of API", "url": "API license URL" } }, "host": "localhost:7777", "basePath": "/", "tags": [{ "name": "article-controller", "description": "Article Controller" }, { "name": "scheduler-example-controller", "description": "Scheduler Example Controller" }], "paths": { "/article/create": { "post": { "tags": ["article-controller"], "summary": "createArticle", "operationId": "createArticleUsingPOST", "consumes": ["application/json"], "produces": ["<em>/</em>"], "parameters": [{ "in": "body", "name": "articleAddRequest", "description": "articleAddRequest", "required": true, "schema": { "$ref": "#/definitions/ArticleAddRequest" } }], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/Mono«string»" } }, "201": { "description": "Created" }, "401": { "description": "Unauthorized" }, "403": { "description": "Forbidden" }, "404": { "description": "Not Found" } }, "deprecated": false } }, "/article/get/{slug}": { "get": { "tags": ["article-controller"], "summary": "findArticleBySlugAndisDeleted", "operationId": "findArticleBySlugAndisDeletedUsingGET", "produces": ["<em>/</em>"], "parameters": [{ "name": "slug", "in": "path", "description": "slug", "required": true, "type": "string" }], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/Mono«ArticleSingleResponse»" } }, "401": { "description": "Unauthorized" }, "403": { "description": "Forbidden" }, "404": { "description": "Not Found" } }, "deprecated": false } }, "/scheduler-example/test-mono-with-scheduler-elastic": { "get": { "tags": ["scheduler-example-controller"], "summary": "testMonoWithSchedulerElastic", "operationId": "testMonoWithSchedulerElasticUsingGET", "produces": ["<em>/</em>"], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/Mono«int»" } }, "401": { "description": "Unauthorized" }, "403": { "description": "Forbidden" }, "404": { "description": "Not Found" } }, "deprecated": false } }, "/scheduler-example/test-mono-with-scheduler-immediate": { "get": { "tags": ["scheduler-example-controller"], "summary": "testMonoWithSchedulerImmediate", "operationId": "testMonoWithSchedulerImmediateUsingGET", "produces": ["<em>/</em>"], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/Mono«int»" } }, "401": { "description": "Unauthorized" }, "403": { "description": "Forbidden" }, "404": { "description": "Not Found" } }, "deprecated": false } }, "/scheduler-example/test-mono-with-scheduler-parallel": { "get": { "tags": ["scheduler-example-controller"], "summary": "testMonoWithSchedulerParallel", "operationId": "testMonoWithSchedulerParallelUsingGET", "produces": ["<em>/</em>"], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/Mono«int»" } }, "401": { "description": "Unauthorized" }, "403": { "description": "Forbidden" }, "404": { "description": "Not Found" } }, "deprecated": false } }, "/scheduler-example/test-mono-with-scheduler-single": { "get": { "tags": ["scheduler-example-controller"], "summary": "testMonoWithSchedulerSingle", "operationId": "testMonoWithSchedulerSingleUsingGET", "produces": ["<em>/</em>"], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/Mono«int»" } }, "401": { "description": "Unauthorized" }, "403": { "description": "Forbidden" }, "404": { "description": "Not Found" } }, "deprecated": false } }, "/scheduler-example/test-mono-with-task-pool-executor-with-timeout": { "get": { "tags": ["scheduler-example-controller"], "summary": "testMonoWithSchedulerFromThreadPoolTaskExecutorWithTimeout", "operationId": "testMonoWithSchedulerFromThreadPoolTaskExecutorWithTimeoutUsingGET", "produces": ["<em>/</em>"], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/Mono«int»" } }, "401": { "description": "Unauthorized" }, "403": { "description": "Forbidden" }, "404": { "description": "Not Found" } }, "deprecated": false } }, "/scheduler-example/test-mono-with-task-pool-executor-without-timeout": { "get": { "tags": ["scheduler-example-controller"], "summary": "testMonoWithSchedulerFromThreadPoolTaskExecutorWithoutTimeout", "operationId": "testMonoWithSchedulerFromThreadPoolTaskExecutorWithoutTimeoutUsingGET", "produces": ["<em>/</em>"], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/Mono«int»" } }, "401": { "description": "Unauthorized" }, "403": { "description": "Forbidden" }, "404": { "description": "Not Found" } }, "deprecated": false } }, "/scheduler-example/test-mono-with-wrong-implementation-task-pool": { "get": { "tags": ["scheduler-example-controller"], "summary": "testMonoWithWrongImplementationThreadPool", "operationId": "testMonoWithWrongImplementationThreadPoolUsingGET", "produces": ["<em>/</em>"], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/Mono«int»" } }, "401": { "description": "Unauthorized" }, "403": { "description": "Forbidden" }, "404": { "description": "Not Found" } }, "deprecated": false } }, "/scheduler-example/test-mono-without-scheduler": { "get": { "tags": ["scheduler-example-controller"], "summary": "testMonoWithoutScheduler", "operationId": "testMonoWithoutSchedulerUsingGET", "produces": ["<em>/</em>"], "responses": { "200": { "description": "OK", "schema": { "$ref": "#/definitions/Mono«int»" } }, "401": { "description": "Unauthorized" }, "403": { "description": "Forbidden" }, "404": { "description": "Not Found" } }, "deprecated": false } } }, "definitions": { "ArticleAddRequest": { "type": "object", "properties": { "author": { "type": "string" }, "content": { "type": "string" }, "slug": { "type": "string" }, "title": { "type": "string" } }, "title": "ArticleAddRequest" }, "ArticleSingleResponse": { "type": "object", "properties": { "author": { "type": "string" }, "content": { "type": "string" }, "slug": { "type": "string" }, "title": { "type": "string" } }, "title": "ArticleSingleResponse" }, "Mono«ArticleSingleResponse»": { "type": "object", "title": "Mono«ArticleSingleResponse»" }, "Mono«int»": { "type": "object", "title": "Mono«int»" }, "Mono«string»": { "type": "object", "title": "Mono«string»" } } } |
Nah, silahkan copas text tersebut dan save ke file dengan extension .json. Sebagai contoh disini gw akan memberikan nama sebagai testing.json. Setelah selesai, kita akan pindah dari bermain java menjadi node js. Kenapa pakai nodejs? Karena library yang convert untuk ubah swagger ke slate cuma ada di nodejs (lebih tepatnya gw baru taunya cuma punya nodejs). Apa perlu install nodejs? Terserah kalian, cuma gw bakal ajarin kalian bagaimana cara jalanin nodejs via docker biar kalian ga cupu-cupu bangetlah hari gini. Gimana kalau mau install nodejs? Ya gapapa, kan laptop punya kalian sendiri kalau gw sih ogah (jadi nyinyir wkwk).
Lalu bagaimana dengan command dockernya sendiri?
1 |
docker run -it --rm --name slate-generator -v "PATH/TO/testing.json/or/you/name/it":/usr/src/app -w /usr/src/app --entrypoint /bin/bash node:12.10.0-slim |
Buat kalian yang sudah mengerti command docker dan ingin menggunakan versi node yang lain gimana? Silahkan, yang gw tulis diatas cuma contoh. Yang berikutnya adalah kita menginstall sebuah package dari npm yakni swagger-to-slate. Untuk cara kerjanya sebagai berikut :

Jadi nantinya kalian akan masuk ke docker containernya, lalu install terlebih dahulu packagenya dengan menggunakan global package. Setelah selesai jalankan dengan command swagger-to-slate -i <file-name.json>, kalau dicontohnya adalah testing.json. Untuk hasil generatenya maka akan terbentuk sebuah file bernama testing.md yang isinya seperti berikut.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 |
--- title: Service Name language_tabs: - shell toc_footers: - <a href="#">Sign Up for a Developer Key</a> - <a href="https://github.com/lavkumarv">Documentation Powered by lav</a> includes: - errors search: true --- # Introduction API Description **Version:** API # /ARTICLE/CREATE ## ***POST*** **Summary:** createArticle ### HTTP Request `***POST*** /article/create` **Parameters** | Name | Located in | Description | Required | Type | | ---- | ---------- | ----------- | -------- | ---- | | articleAddRequest | body | articleAddRequest | Yes | | **Responses** | Code | Description | | ---- | ----------- | | 200 | OK | | 201 | Created | | 401 | Unauthorized | | 403 | Forbidden | | 404 | Not Found | # /ARTICLE/GET/{SLUG} ## ***GET*** **Summary:** findArticleBySlugAndisDeleted ### HTTP Request `***GET*** /article/get/{slug}` **Parameters** | Name | Located in | Description | Required | Type | | ---- | ---------- | ----------- | -------- | ---- | | slug | path | slug | Yes | string | **Responses** | Code | Description | | ---- | ----------- | | 200 | OK | | 401 | Unauthorized | | 403 | Forbidden | | 404 | Not Found | # /SCHEDULER-EXAMPLE/TEST-MONO-WITH-SCHEDULER-ELASTIC ## ***GET*** **Summary:** testMonoWithSchedulerElastic ### HTTP Request `***GET*** /scheduler-example/test-mono-with-scheduler-elastic` **Responses** | Code | Description | | ---- | ----------- | | 200 | OK | | 401 | Unauthorized | | 403 | Forbidden | | 404 | Not Found | # /SCHEDULER-EXAMPLE/TEST-MONO-WITH-SCHEDULER-IMMEDIATE ## ***GET*** **Summary:** testMonoWithSchedulerImmediate ### HTTP Request `***GET*** /scheduler-example/test-mono-with-scheduler-immediate` **Responses** | Code | Description | | ---- | ----------- | | 200 | OK | | 401 | Unauthorized | | 403 | Forbidden | | 404 | Not Found | # /SCHEDULER-EXAMPLE/TEST-MONO-WITH-SCHEDULER-PARALLEL ## ***GET*** **Summary:** testMonoWithSchedulerParallel ### HTTP Request `***GET*** /scheduler-example/test-mono-with-scheduler-parallel` **Responses** | Code | Description | | ---- | ----------- | | 200 | OK | | 401 | Unauthorized | | 403 | Forbidden | | 404 | Not Found | # /SCHEDULER-EXAMPLE/TEST-MONO-WITH-SCHEDULER-SINGLE ## ***GET*** **Summary:** testMonoWithSchedulerSingle ### HTTP Request `***GET*** /scheduler-example/test-mono-with-scheduler-single` **Responses** | Code | Description | | ---- | ----------- | | 200 | OK | | 401 | Unauthorized | | 403 | Forbidden | | 404 | Not Found | # /SCHEDULER-EXAMPLE/TEST-MONO-WITH-TASK-POOL-EXECUTOR-WITH-TIMEOUT ## ***GET*** **Summary:** testMonoWithSchedulerFromThreadPoolTaskExecutorWithTimeout ### HTTP Request `***GET*** /scheduler-example/test-mono-with-task-pool-executor-with-timeout` **Responses** | Code | Description | | ---- | ----------- | | 200 | OK | | 401 | Unauthorized | | 403 | Forbidden | | 404 | Not Found | # /SCHEDULER-EXAMPLE/TEST-MONO-WITH-TASK-POOL-EXECUTOR-WITHOUT-TIMEOUT ## ***GET*** **Summary:** testMonoWithSchedulerFromThreadPoolTaskExecutorWithoutTimeout ### HTTP Request `***GET*** /scheduler-example/test-mono-with-task-pool-executor-without-timeout` **Responses** | Code | Description | | ---- | ----------- | | 200 | OK | | 401 | Unauthorized | | 403 | Forbidden | | 404 | Not Found | # /SCHEDULER-EXAMPLE/TEST-MONO-WITH-WRONG-IMPLEMENTATION-TASK-POOL ## ***GET*** **Summary:** testMonoWithWrongImplementationThreadPool ### HTTP Request `***GET*** /scheduler-example/test-mono-with-wrong-implementation-task-pool` **Responses** | Code | Description | | ---- | ----------- | | 200 | OK | | 401 | Unauthorized | | 403 | Forbidden | | 404 | Not Found | # /SCHEDULER-EXAMPLE/TEST-MONO-WITHOUT-SCHEDULER ## ***GET*** **Summary:** testMonoWithoutScheduler ### HTTP Request `***GET*** /scheduler-example/test-mono-without-scheduler` **Responses** | Code | Description | | ---- | ----------- | | 200 | OK | | 401 | Unauthorized | | 403 | Forbidden | | 404 | Not Found | |
Lalu untuk testing.md nya bisa dicopaskan ke index.html.md di slatenya. Bagi yang kelewatan bagaimana jalankan docker di slate bisa cek post gw disini. Kalau sudah mengcopy, maka akan hasilnya akan seperti berikut :

Demikian sedikit tutorial dari gw, kalau ada yang bilang ga rapi seperti yang gw bilang sebelumnya butuh namanya update-update dikit tapi at least effortnya ga gede lah.