API Documentation Formatting Library
Meteor Platform API Documentation Formatting Library w/ Swagger.
Installation
npm i git+ssh://git@repository.meteor.asia/mtr-platform/libs/apidoc
Penggunaan
Buat file doc.js
di dalam root folder atau index.js
di dalam folder doc dengan format seperti berikut:
const description = 'API description';
const schemes = ['https', 'http'];
const tags = [
{
name: 'Tag Name',
description: 'Tag description.',
},
];
const paths = {
'path-name': {
get: {
tags: ['Tag Name'],
description: 'Endpoint description',
auth: true,
dataTable: [
{ name: 'id', searchable: true },
{ name: 'name', searchable: true },
{ name: 'phone', searchable: true },
{ name: 'email', searchable: true },
],
parameters: [
{
name: 'status',
in: 'query',
type: 'string',
default: '',
description: 'Index only specific status',
},
],
results: {
200: {
total: 1,
total_filtered: 1,
total_displayed: 1,
total_page: 1,
page: 1,
data: [
{
id: '3ec79570-75f7-11e9-8901-3778b1fc30d4',
name: 'John Doe',
phone: '88801426139',
email: 'john.doe@yayasan.id',
},
],
},
},
},
},
'/path-name/{id}': {
post: {
tags: ['Tag Name'],
description: 'Endpoint description',
auth: true,
parameters: [
{
name: 'id',
in: 'path',
type: 'string',
required: true,
default: '2017ace8-3785-11ea-b295-84ef18e0817f',
description: 'Parameter description',
validation: ['Not empty', 'ID is in pathIDs'],
},
],
results: {
200: {
id: '23b97ce8-1944-11e9-9620-d5ae65e64e7e',
int: 1579586389,
arr: ['OK', 'YES'],
obj: { ok: 1, no: 0 },
is: true,
},
403: {
auth_token: {
value: 'jwt expired',
msg: 'TokenExpiredError',
},
},
},
},
},
};
module.exports = {
description, schemes, tags, paths,
};
Deklarasikan module library di dalam file xxx-gateway/api.js
.
const jsonDoc = require('mtr-apidoc');
module.exports = (router) => {
router.get('/', jsonDoc);
};