From 06ee0b1112d19a3c2879c4dad899d2ace9027211 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Fri, 15 Jul 2022 10:12:58 -0500 Subject: [PATCH] fix(openapi): clearer copy, smol refactors (#536) --- src/cmds/openapi.js | 10 ++++------ src/lib/prepareOas.js | 5 ++--- src/lib/streamSpecToRegistry.js | 6 ++---- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/src/cmds/openapi.js b/src/cmds/openapi.js index e24d264cf..942746970 100644 --- a/src/cmds/openapi.js +++ b/src/cmds/openapi.js @@ -141,11 +141,10 @@ module.exports = class OpenAPICommand { function createSpec() { options.method = 'post'; - const text = 'Creating your API docs in ReadMe...'; - spinner.start(text); + spinner.start('Creating your API docs in ReadMe...'); return fetch(`${config.get('host')}/api/v1/api-specification`, options).then(res => { if (res.ok) { - spinner.succeed(`${text} done! 🦉`); + spinner.succeed(`${spinner.text} done! 🦉`); return success(res); } spinner.fail(); @@ -156,11 +155,10 @@ module.exports = class OpenAPICommand { function updateSpec(specId) { isUpdate = true; options.method = 'put'; - const text = 'Updating your API docs in ReadMe...'; - spinner.start(text); + spinner.start('Updating your API docs in ReadMe...'); return fetch(`${config.get('host')}/api/v1/api-specification/${specId}`, options).then(res => { if (res.ok) { - spinner.succeed(`${text} done! 🦉`); + spinner.succeed(`${spinner.text} done! 🦉`); return success(res); } spinner.fail(); diff --git a/src/lib/prepareOas.js b/src/lib/prepareOas.js index 1d144c4f8..51e6c4fd6 100644 --- a/src/lib/prepareOas.js +++ b/src/lib/prepareOas.js @@ -10,8 +10,7 @@ const ora = require('ora'); * return a bundled spec (defaults to false) */ module.exports = async function prepare(path, bundle = false) { - const text = `Validating API definition located at ${path}...`; - const spinner = ora({ text, ...oraOptions() }).start(); + const spinner = ora({ text: `Validating API definition located at ${path}...`, ...oraOptions() }).start(); debug(`about to normalize spec located at ${path}`); const oas = new OASNormalize(path, { colorizeErrors: true, enablePaths: true }); @@ -22,7 +21,7 @@ module.exports = async function prepare(path, bundle = false) { debug(`raw validation error object: ${JSON.stringify(err)}`); throw err; }); - spinner.succeed(`${text} done! ✅`); + spinner.succeed(`${spinner.text} done! ✅`); debug('👇👇👇👇👇 spec validated! logging spec below 👇👇👇👇👇'); debug(api); diff --git a/src/lib/streamSpecToRegistry.js b/src/lib/streamSpecToRegistry.js index e220cfb7b..1ff8c8ec1 100644 --- a/src/lib/streamSpecToRegistry.js +++ b/src/lib/streamSpecToRegistry.js @@ -7,8 +7,6 @@ const fs = require('fs'); const ora = require('ora'); const { file: tmpFile } = require('tmp-promise'); -const text = 'Uploading API Definition to ReadMe...'; - /** * Uploads a spec to the API registry for usage in ReadMe * @@ -16,7 +14,7 @@ const text = 'Uploading API Definition to ReadMe...'; * @returns {String} a UUID in the API registry */ module.exports = async function streamSpecToRegistry(spec) { - const spinner = ora({ text, ...oraOptions() }).start(); + const spinner = ora({ text: 'Staging your API definition for upload...', ...oraOptions() }).start(); // Create a temporary file to write the bundled spec to, // which we will then stream into the form data body const { path } = await tmpFile({ prefix: 'rdme-openapi-', postfix: '.json' }); @@ -39,7 +37,7 @@ module.exports = async function streamSpecToRegistry(spec) { return fetch(`${config.get('host')}/api/v1/api-registry`, options) .then(res => handleRes(res)) .then(body => { - spinner.succeed(`${text} done! 🚀`); + spinner.succeed(`${spinner.text} done! 🚀`); return body.registryUUID; }) .catch(e => {