From e8f3d0eda2fd98f2ab86f19f1f34042ed44cd2f4 Mon Sep 17 00:00:00 2001 From: David Diaz Date: Sat, 21 Oct 2017 01:17:15 -0600 Subject: [PATCH] Added support for a documentation field in the beau.yaml file. This field will be use to prettify the output of certain tools and to document apis. --- bin/beau | 10 ++++++++-- examples/jsonplaceholder.yml | 7 +++++++ request.js | 4 +++- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/bin/beau b/bin/beau index 1f50117..ac8b4d6 100755 --- a/bin/beau +++ b/bin/beau @@ -56,8 +56,14 @@ if ( } if (program.cleanList) { - beau.requests.list.forEach(({ VERB, ALIAS, ENDPOINT }) => { - console.log(`${VERB}\t${ALIAS}\t${ENDPOINT}`); + beau.requests.list.forEach(({ VERB, ALIAS, ENDPOINT, DOCUMENTATION }) => { + if (typeof DOCUMENTATION !== 'undefined') { + let {title, description} = DOCUMENTATION; + console.log(`${VERB}\t${ALIAS}\t${ENDPOINT}\t${title}\t${description}`); + + } else { + console.log(`${VERB}\t${ALIAS}\t${ENDPOINT}`); + } }); } diff --git a/examples/jsonplaceholder.yml b/examples/jsonplaceholder.yml index 3e851ce..130bb8b 100644 --- a/examples/jsonplaceholder.yml +++ b/examples/jsonplaceholder.yml @@ -3,11 +3,18 @@ host: 'http://jsonplaceholder.typicode.com' GET /posts/: alias: posts + documentation: + title: Fetch Posts + description: Fetches all posts available. POST /posts/: alias: new-post + documentation: + title: New Post GET /users/$posts.body.0.userId: alias: post-user + documentation: + description: Fetches the user for a give post. params: hello: 'world' diff --git a/request.js b/request.js index 0f7e0d1..f976b5a 100644 --- a/request.js +++ b/request.js @@ -10,7 +10,7 @@ class Request { Object.keys(req).forEach(k => config[k.toUpperCase()] = req[k]); - let { REQUEST, ALIAS, PAYLOAD, HOST, PARAMS, HEADERS } = config; + let { REQUEST, ALIAS, PAYLOAD, HOST, PARAMS, HEADERS, DOCUMENTATION } = config; let { verb, endpoint } = this.parseRequest(REQUEST); this.VERB = verb; @@ -23,6 +23,8 @@ class Request { this.ALIAS = ALIAS; this.DEPENDENCIES = this.findDependencies(req); + this.DOCUMENTATION = DOCUMENTATION; + this.list = list; }