Skip to content

Commit

Permalink
fix(openapi): clearer copy, smol refactors (#536)
Browse files Browse the repository at this point in the history
  • Loading branch information
kanadgupta authored Jul 15, 2022
1 parent 122ba5c commit 06ee0b1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
10 changes: 4 additions & 6 deletions src/cmds/openapi.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down
5 changes: 2 additions & 3 deletions src/lib/prepareOas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand All @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions src/lib/streamSpecToRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,14 @@ 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
*
* @param {String} spec path to a bundled/validated spec file
* @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' });
Expand All @@ -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 => {
Expand Down

0 comments on commit 06ee0b1

Please sign in to comment.