From 8a5619c7b71ed9f8525c1be0c016077239b27c73 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Fri, 5 Aug 2022 15:22:40 -0700 Subject: [PATCH 01/20] docs: add some JSDocs for getProjectVersion --- src/lib/versionSelect.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/lib/versionSelect.js b/src/lib/versionSelect.js index f33edcf61..cbd601e92 100644 --- a/src/lib/versionSelect.js +++ b/src/lib/versionSelect.js @@ -5,6 +5,15 @@ const APIError = require('./apiError'); const fetch = require('./fetch'); const { cleanHeaders, handleRes } = require('./fetch'); +/** + * Validates and returns a project version. + * + * @param {String} versionFlag version input parameter + * @param {String} key project API key + * @param {Boolean} allowNewVersion if true, goes through prompt flow + * for creating a new project version + * @returns {String} a cleaned up project version + */ async function getProjectVersion(versionFlag, key, allowNewVersion) { try { if (versionFlag) { From a39abe7aa2bf9ef6da179063b027bae4500abc8a Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Fri, 5 Aug 2022 15:24:52 -0700 Subject: [PATCH 02/20] fix(openapi): add trailing period to param description --- src/cmds/openapi.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cmds/openapi.js b/src/cmds/openapi.js index 6eedde65b..05402c7c7 100644 --- a/src/cmds/openapi.js +++ b/src/cmds/openapi.js @@ -32,7 +32,7 @@ module.exports = class OpenAPICommand { name: 'id', type: String, description: - "Unique identifier for your API definition. Use this if you're re-uploading an existing API definition", + "Unique identifier for your API definition. Use this if you're re-uploading an existing API definition.", }, { name: 'version', From 36e74ddfe28ce9fb27ee565ae0f287743554d938 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Fri, 5 Aug 2022 15:33:37 -0700 Subject: [PATCH 03/20] refactor: consolidate version opt descriptions --- src/cmds/categories/create.js | 7 ++----- src/cmds/categories/index.js | 7 ++----- src/cmds/docs/edit.js | 7 ++----- src/cmds/docs/index.js | 7 ++----- src/cmds/docs/single.js | 7 ++----- src/cmds/openapi.js | 7 ++----- src/cmds/versions/update.js | 7 ++----- src/lib/versionOpt.js | 6 ++++++ 8 files changed, 20 insertions(+), 35 deletions(-) create mode 100644 src/lib/versionOpt.js diff --git a/src/cmds/categories/create.js b/src/cmds/categories/create.js index 4d01594d2..0f4a5d18c 100644 --- a/src/cmds/categories/create.js +++ b/src/cmds/categories/create.js @@ -5,6 +5,7 @@ const { debug } = require('../../lib/logger'); const fetch = require('../../lib/fetch'); const getCategories = require('../../lib/getCategories'); const { getProjectVersion } = require('../../lib/versionSelect'); +const versionOpt = require('../../lib/versionOpt'); module.exports = class CategoriesCreateCommand { constructor() { @@ -21,11 +22,7 @@ module.exports = class CategoriesCreateCommand { type: String, description: 'Project API key', }, - { - name: 'version', - type: String, - description: 'Project version', - }, + versionOpt, { name: 'title', type: String, diff --git a/src/cmds/categories/index.js b/src/cmds/categories/index.js index 116b1cd54..698715f7c 100644 --- a/src/cmds/categories/index.js +++ b/src/cmds/categories/index.js @@ -1,6 +1,7 @@ const { debug } = require('../../lib/logger'); const { getProjectVersion } = require('../../lib/versionSelect'); const getCategories = require('../../lib/getCategories'); +const versionOpt = require('../../lib/versionOpt'); module.exports = class CategoriesCommand { constructor() { @@ -16,11 +17,7 @@ module.exports = class CategoriesCommand { type: String, description: 'Project API key', }, - { - name: 'version', - type: String, - description: 'Project version', - }, + versionOpt, ]; } diff --git a/src/cmds/docs/edit.js b/src/cmds/docs/edit.js index 2fccae025..e553715a3 100644 --- a/src/cmds/docs/edit.js +++ b/src/cmds/docs/edit.js @@ -7,6 +7,7 @@ const { getProjectVersion } = require('../../lib/versionSelect'); const fetch = require('../../lib/fetch'); const { cleanHeaders, handleRes } = require('../../lib/fetch'); const { debug, info } = require('../../lib/logger'); +const versionOpt = require('../../lib/versionOpt'); const writeFile = promisify(fs.writeFile); const readFile = promisify(fs.readFile); @@ -27,11 +28,7 @@ module.exports = class EditDocsCommand { type: String, description: 'Project API key', }, - { - name: 'version', - type: String, - description: 'Project version', - }, + versionOpt, { name: 'slug', type: String, diff --git a/src/cmds/docs/index.js b/src/cmds/docs/index.js index 3ddd47d56..f28ca9d12 100644 --- a/src/cmds/docs/index.js +++ b/src/cmds/docs/index.js @@ -5,6 +5,7 @@ const { getProjectVersion } = require('../../lib/versionSelect'); const { debug } = require('../../lib/logger'); const pushDoc = require('../../lib/pushDoc'); const { readdirRecursive } = require('../../lib/pushDoc'); +const versionOpt = require('../../lib/versionOpt'); module.exports = class DocsCommand { constructor() { @@ -21,11 +22,7 @@ module.exports = class DocsCommand { type: String, description: 'Project API key', }, - { - name: 'version', - type: String, - description: 'Project version', - }, + versionOpt, { name: 'folder', type: String, diff --git a/src/cmds/docs/single.js b/src/cmds/docs/single.js index 5949bd688..352adf671 100644 --- a/src/cmds/docs/single.js +++ b/src/cmds/docs/single.js @@ -4,6 +4,7 @@ const config = require('config'); const { debug } = require('../../lib/logger'); const { getProjectVersion } = require('../../lib/versionSelect'); const pushDoc = require('../../lib/pushDoc'); +const versionOpt = require('../../lib/versionOpt'); module.exports = class SingleDocCommand { constructor() { @@ -20,11 +21,7 @@ module.exports = class SingleDocCommand { type: String, description: 'Project API key', }, - { - name: 'version', - type: String, - description: 'Project version', - }, + versionOpt, { name: 'filePath', type: String, diff --git a/src/cmds/openapi.js b/src/cmds/openapi.js index 05402c7c7..77460b464 100644 --- a/src/cmds/openapi.js +++ b/src/cmds/openapi.js @@ -12,6 +12,7 @@ const prepareOas = require('../lib/prepareOas'); const { prompt } = require('enquirer'); const promptOpts = require('../lib/prompts'); const streamSpecToRegistry = require('../lib/streamSpecToRegistry'); +const versionOpt = require('../lib/versionOpt'); module.exports = class OpenAPICommand { constructor() { @@ -34,11 +35,7 @@ module.exports = class OpenAPICommand { description: "Unique identifier for your API definition. Use this if you're re-uploading an existing API definition.", }, - { - name: 'version', - type: String, - description: 'Project version', - }, + versionOpt, { name: 'spec', type: String, diff --git a/src/cmds/versions/update.js b/src/cmds/versions/update.js index 613d0f1fc..40a2d78c1 100644 --- a/src/cmds/versions/update.js +++ b/src/cmds/versions/update.js @@ -5,6 +5,7 @@ const { getProjectVersion } = require('../../lib/versionSelect'); const fetch = require('../../lib/fetch'); const { cleanHeaders, handleRes } = require('../../lib/fetch'); const { debug } = require('../../lib/logger'); +const versionOpt = require('../../lib/versionOpt'); module.exports = class UpdateVersionCommand { constructor() { @@ -20,11 +21,7 @@ module.exports = class UpdateVersionCommand { type: String, description: 'Project API key', }, - { - name: 'version', - type: String, - description: 'Project version', - }, + versionOpt, { name: 'codename', type: String, diff --git a/src/lib/versionOpt.js b/src/lib/versionOpt.js new file mode 100644 index 000000000..461a2e523 --- /dev/null +++ b/src/lib/versionOpt.js @@ -0,0 +1,6 @@ +module.exports = { + name: 'version', + type: String, + description: + 'Project version. If running command in a CI environment and this option is not passed, the main project version will be used.', +}; From 4be032d2a56ade2d0fff859dc54208103dfd71e9 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Fri, 5 Aug 2022 15:46:52 -0700 Subject: [PATCH 04/20] test: update snapshots --- __tests__/__snapshots__/index.test.js.snap | 15 +++++++++------ __tests__/lib/commands.test.js | 4 +++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/__tests__/__snapshots__/index.test.js.snap b/__tests__/__snapshots__/index.test.js.snap index 8e3c228af..c4f2cf5ab 100644 --- a/__tests__/__snapshots__/index.test.js.snap +++ b/__tests__/__snapshots__/index.test.js.snap @@ -12,8 +12,9 @@ Options --key string Project API key --id string Unique identifier for your API definition. Use this if you're re- - uploading an existing API definition - --version string Project version + uploading an existing API definition. + --version string Project version. If running command in a CI environment and this + option is not passed, the main project version will be used. --workingDirectory string Working directory (for usage with relative external references) -h, --help Display this usage guide @@ -36,8 +37,9 @@ Options --key string Project API key --id string Unique identifier for your API definition. Use this if you're re- - uploading an existing API definition - --version string Project version + uploading an existing API definition. + --version string Project version. If running command in a CI environment and this + option is not passed, the main project version will be used. --workingDirectory string Working directory (for usage with relative external references) -h, --help Display this usage guide @@ -60,8 +62,9 @@ Options --key string Project API key --id string Unique identifier for your API definition. Use this if you're re- - uploading an existing API definition - --version string Project version + uploading an existing API definition. + --version string Project version. If running command in a CI environment and this + option is not passed, the main project version will be used. --workingDirectory string Working directory (for usage with relative external references) -h, --help Display this usage guide diff --git a/__tests__/lib/commands.test.js b/__tests__/lib/commands.test.js index f6aeb641a..fceaa13b2 100644 --- a/__tests__/lib/commands.test.js +++ b/__tests__/lib/commands.test.js @@ -49,7 +49,9 @@ describe('utils', () => { } expect(arg.description).toBe( - cmd.command !== 'versions' ? 'Project version' : 'A specific project version to view' + cmd.command !== 'versions' + ? 'Project version. If running command in a CI environment and this option is not passed, the main project version will be used.' + : 'A specific project version to view' ); } }); From f937dc104a45d3da671654c480a39616f19491f4 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 8 Aug 2022 18:10:32 -0500 Subject: [PATCH 05/20] feat: initial pass at CI version handling --- src/lib/versionSelect.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/lib/versionSelect.js b/src/lib/versionSelect.js index cbd601e92..86112da48 100644 --- a/src/lib/versionSelect.js +++ b/src/lib/versionSelect.js @@ -1,9 +1,12 @@ -const { prompt } = require('enquirer'); -const promptOpts = require('./prompts'); +const ciDetect = require('@npmcli/ci-detect'); const config = require('config'); +const { prompt } = require('enquirer'); + const APIError = require('./apiError'); -const fetch = require('./fetch'); const { cleanHeaders, handleRes } = require('./fetch'); +const fetch = require('./fetch'); +const promptOpts = require('./prompts'); +const { warn } = require('./logger'); /** * Validates and returns a project version. @@ -25,6 +28,11 @@ async function getProjectVersion(versionFlag, key, allowNewVersion) { .then(res => res.version); } + if ((ciDetect() && process.env.NODE_ENV !== 'testing') || process.env.TEST_CI) { + warn('No `--version` parameter detected in current CI environment. Defaulting to main version.'); + return undefined; + } + const versionList = await fetch(`${config.get('host')}/api/v1/version`, { method: 'get', headers: cleanHeaders(key), From f2fb63d1aebf6556231dfee9a7126368587d60d5 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 8 Aug 2022 18:19:37 -0500 Subject: [PATCH 06/20] feat: initial pass at `useSpecVersion` flag --- src/cmds/openapi.js | 25 ++++++++++++++++++------- src/lib/prepareOas.js | 5 ++++- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/cmds/openapi.js b/src/cmds/openapi.js index 77460b464..4cee6887b 100644 --- a/src/cmds/openapi.js +++ b/src/cmds/openapi.js @@ -46,12 +46,18 @@ module.exports = class OpenAPICommand { type: String, description: 'Working directory (for usage with relative external references)', }, + { + name: 'useSpecVersion', + type: Boolean, + description: + 'Uses the version listed in the `info.version` field in the API definition for the project version parameter.', + }, ]; } async run(opts) { - const { key, id, spec, version, workingDirectory } = opts; - let selectedVersion; + const { key, id, spec, useSpecVersion, version, workingDirectory } = opts; + let selectedVersion = version; let isUpdate; const spinner = ora({ ...oraOptions() }); @@ -70,16 +76,21 @@ module.exports = class OpenAPICommand { return Promise.reject(new Error('No project API key provided. Please use `--key`.')); } + // Reason we're hardcoding in command here is because `swagger` command + // relies on this and we don't want to use `swagger` in this function + const { bundledSpec, specPath, specType, specVersion } = await prepareOas(spec, 'openapi'); + + if (useSpecVersion) { + debug(`using spec version: ${specVersion}`); + selectedVersion = specVersion; + } + if (!id) { - selectedVersion = await getProjectVersion(version, key, true); + selectedVersion = await getProjectVersion(selectedVersion, key, true); } debug(`selectedVersion: ${selectedVersion}`); - // Reason we're hardcoding in command here is because `swagger` command - // relies on this and we don't want to use `swagger` in this function - const { bundledSpec, specPath, specType } = await prepareOas(spec, 'openapi'); - async function success(data) { const message = !isUpdate ? `You've successfully uploaded a new ${specType} file to your ReadMe project!` diff --git a/src/lib/prepareOas.js b/src/lib/prepareOas.js index 339e35afd..7b543f0c0 100644 --- a/src/lib/prepareOas.js +++ b/src/lib/prepareOas.js @@ -61,6 +61,9 @@ module.exports = async function prepare(path, command) { const specType = api.swagger ? 'Swagger' : 'OpenAPI'; debug(`spec type: ${specType}`); + const specVersion = api?.info?.version; + debug(`version in spec: ${specVersion}`); + let bundledSpec = ''; if (command === 'openapi') { @@ -71,5 +74,5 @@ module.exports = async function prepare(path, command) { debug('spec bundled'); } - return { bundledSpec, specPath, specType }; + return { bundledSpec, specPath, specType, specVersion }; }; From 313505c0f1041ea8220636b9ce679098de299d3e Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 8 Aug 2022 18:19:56 -0500 Subject: [PATCH 07/20] test: fix snapshots --- __tests__/__snapshots__/index.test.js.snap | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/__tests__/__snapshots__/index.test.js.snap b/__tests__/__snapshots__/index.test.js.snap index c4f2cf5ab..70dc5b56b 100644 --- a/__tests__/__snapshots__/index.test.js.snap +++ b/__tests__/__snapshots__/index.test.js.snap @@ -16,6 +16,8 @@ Options --version string Project version. If running command in a CI environment and this option is not passed, the main project version will be used. --workingDirectory string Working directory (for usage with relative external references) + --useSpecVersion Uses the version listed in the \`info.version\` field in the API + definition for the project version parameter. -h, --help Display this usage guide Related commands @@ -41,6 +43,8 @@ Options --version string Project version. If running command in a CI environment and this option is not passed, the main project version will be used. --workingDirectory string Working directory (for usage with relative external references) + --useSpecVersion Uses the version listed in the \`info.version\` field in the API + definition for the project version parameter. -h, --help Display this usage guide Related commands @@ -66,6 +70,8 @@ Options --version string Project version. If running command in a CI environment and this option is not passed, the main project version will be used. --workingDirectory string Working directory (for usage with relative external references) + --useSpecVersion Uses the version listed in the \`info.version\` field in the API + definition for the project version parameter. -h, --help Display this usage guide Related commands From 8ebaf2c82e61e55ea634b8413476f1e8dc9f5b28 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 8 Aug 2022 18:20:38 -0500 Subject: [PATCH 08/20] test: fix test This test broke because we slightly refactored the order in which we do version selection, so it had a nock that is no longer being hit. --- __tests__/cmds/openapi.test.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/__tests__/cmds/openapi.test.js b/__tests__/cmds/openapi.test.js index 927d12951..bb7d5c0a3 100644 --- a/__tests__/cmds/openapi.test.js +++ b/__tests__/cmds/openapi.test.js @@ -365,15 +365,10 @@ describe('rdme openapi', () => { return mock.done(); }); - it('should error if no file was provided or able to be discovered', async () => { - const mock = getApiNock() - .get(`/api/v1/version/${version}`) - .basicAuth({ user: key }) - .reply(200, { version: '1.0.0' }); - - await expect(openapi.run({ key, version })).rejects.toThrow(/We couldn't find an OpenAPI or Swagger definition./); - - return mock.done(); + it('should error if no file was provided or able to be discovered', () => { + return expect(openapi.run({ key, version })).rejects.toThrow( + /We couldn't find an OpenAPI or Swagger definition./ + ); }); it('should throw an error if an invalid OpenAPI 3.0 definition is supplied', () => { From 6f87f8040c719f8f44f22f2d6f0b00aece78a314 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 8 Aug 2022 18:26:33 -0500 Subject: [PATCH 09/20] test: add coverage for various version edge cases --- .../petstore-simple-weird-version.json | 61 ++++++++++ __tests__/cmds/openapi.test.js | 104 ++++++++++++++++++ 2 files changed, 165 insertions(+) create mode 100644 __tests__/__fixtures__/petstore-simple-weird-version.json diff --git a/__tests__/__fixtures__/petstore-simple-weird-version.json b/__tests__/__fixtures__/petstore-simple-weird-version.json new file mode 100644 index 000000000..a4256e56e --- /dev/null +++ b/__tests__/__fixtures__/petstore-simple-weird-version.json @@ -0,0 +1,61 @@ +{ + "openapi": "3.0.0", + "info": { + "version": "1.2.3", + "title": "Single Path", + "description": "This is a slimmed down single path version of the Petstore definition." + }, + "servers": [ + { + "url": "https://httpbin.org" + } + ], + "paths": { + "/pet/{id}": { + "parameters": [ + { + "name": "id", + "in": "path", + "required": true, + "schema": { + "type": "integer" + } + } + ], + "put": { + "tags": ["pet"], + "summary": "Update a pet", + "description": "This operation will update a pet in the database.", + "responses": { + "400": { + "description": "Invalid id value" + } + }, + "security": [ + { + "apiKey": [] + } + ] + }, + "get": { + "tags": ["pet"], + "summary": "Find a pet", + "description": "This operation will find a pet in the database.", + "responses": { + "400": { + "description": "Invalid status value" + } + }, + "security": [] + } + } + }, + "components": { + "securitySchemes": { + "apiKey": { + "type": "http", + "scheme": "basic" + } + } + } +} diff --git a/__tests__/cmds/openapi.test.js b/__tests__/cmds/openapi.test.js index bb7d5c0a3..b43c790c9 100644 --- a/__tests__/cmds/openapi.test.js +++ b/__tests__/cmds/openapi.test.js @@ -270,6 +270,110 @@ describe('rdme openapi', () => { }); describe('versioning', () => { + it('should use version from version param properly', async () => { + expect.assertions(2); + let requestBody = null; + const registryUUID = getRandomRegistryId(); + const mock = getApiNock() + .get(`/api/v1/version/${version}`) + .basicAuth({ user: key }) + .reply(200, { version: '1.0.0' }) + .post('/api/v1/api-registry', body => { + requestBody = body.substring(body.indexOf('{'), body.lastIndexOf('}') + 1); + requestBody = JSON.parse(requestBody); + + return body.match('form-data; name="spec"'); + }) + .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }) + .get('/api/v1/api-specification') + .basicAuth({ user: key }) + .reply(200, []) + .post('/api/v1/api-specification', { registryUUID }) + .basicAuth({ user: key }) + .reply(function (uri, rBody, cb) { + expect(this.req.headers['x-readme-version'][0]).toBe(version); + return cb(null, [201, { _id: 1 }, { location: exampleRefLocation }]); + }); + + const spec = './__tests__/__fixtures__/ref-oas/petstore.json'; + + await expect(openapi.run({ spec, key, version })).resolves.toBe(successfulUpload(spec)); + + return mock.done(); + }); + + it('should use version from spec file properly', async () => { + expect.assertions(2); + const specVersion = '1.2.3'; + let requestBody = null; + const registryUUID = getRandomRegistryId(); + const mock = getApiNock() + .get(`/api/v1/version/${specVersion}`) + .basicAuth({ user: key }) + .reply(200, { version: specVersion }) + .post('/api/v1/api-registry', body => { + requestBody = body.substring(body.indexOf('{'), body.lastIndexOf('}') + 1); + requestBody = JSON.parse(requestBody); + + return body.match('form-data; name="spec"'); + }) + .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }) + .get('/api/v1/api-specification') + .basicAuth({ user: key }) + .reply(200, []) + .post('/api/v1/api-specification', { registryUUID }) + .basicAuth({ user: key }) + .reply(function (uri, rBody, cb) { + expect(this.req.headers['x-readme-version'][0]).toBe(specVersion); + return cb(null, [201, { _id: 1 }, { location: exampleRefLocation }]); + }); + + const spec = './__tests__/__fixtures__/petstore-simple-weird-version.json'; + + await expect(openapi.run({ spec, key, version, useSpecVersion: true })).resolves.toBe(successfulUpload(spec)); + + return mock.done(); + }); + + describe('CI version handling', () => { + beforeEach(() => { + process.env.TEST_CI = 'true'; + }); + + afterEach(() => { + delete process.env.TEST_CI; + }); + + it('should omit version header in CI environment', async () => { + expect.assertions(2); + let requestBody = null; + const registryUUID = getRandomRegistryId(); + const mock = getApiNock() + .post('/api/v1/api-registry', body => { + requestBody = body.substring(body.indexOf('{'), body.lastIndexOf('}') + 1); + requestBody = JSON.parse(requestBody); + + return body.match('form-data; name="spec"'); + }) + .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }) + .get('/api/v1/api-specification') + .basicAuth({ user: key }) + .reply(200, []) + .post('/api/v1/api-specification', { registryUUID }) + .basicAuth({ user: key }) + .reply(function (uri, rBody, cb) { + expect(this.req.headers['x-readme-version']).toBeUndefined(); + return cb(null, [201, { _id: 1 }, { location: exampleRefLocation }]); + }); + + const spec = './__tests__/__fixtures__/ref-oas/petstore.json'; + + await expect(openapi.run({ spec, key })).resolves.toBe(successfulUpload(spec)); + + return mock.done(); + }); + }); + it('should error if version flag sent to API returns a 404', async () => { const invalidVersion = 'v1000'; From 8b445fb38c062d556cc7e65ec14189479053af25 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 8 Aug 2022 18:32:41 -0500 Subject: [PATCH 10/20] test: use different file Just as an additional sanity check, gonna use the weird version file again so we can ensure its version is not being adhered to unless the corresponding flag is passed. --- __tests__/cmds/openapi.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/cmds/openapi.test.js b/__tests__/cmds/openapi.test.js index b43c790c9..d8bcb3e5d 100644 --- a/__tests__/cmds/openapi.test.js +++ b/__tests__/cmds/openapi.test.js @@ -295,7 +295,7 @@ describe('rdme openapi', () => { return cb(null, [201, { _id: 1 }, { location: exampleRefLocation }]); }); - const spec = './__tests__/__fixtures__/ref-oas/petstore.json'; + const spec = './__tests__/__fixtures__/petstore-simple-weird-version.json'; await expect(openapi.run({ spec, key, version })).resolves.toBe(successfulUpload(spec)); From ea5dff116a471b092329379c1ba8f2e64270f066 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 8 Aug 2022 18:41:16 -0500 Subject: [PATCH 11/20] chore(openapi): alphabetize opts --- __tests__/__snapshots__/index.test.js.snap | 6 +++--- src/cmds/openapi.js | 10 +++++----- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/__tests__/__snapshots__/index.test.js.snap b/__tests__/__snapshots__/index.test.js.snap index 70dc5b56b..c26f0fa02 100644 --- a/__tests__/__snapshots__/index.test.js.snap +++ b/__tests__/__snapshots__/index.test.js.snap @@ -15,9 +15,9 @@ Options uploading an existing API definition. --version string Project version. If running command in a CI environment and this option is not passed, the main project version will be used. - --workingDirectory string Working directory (for usage with relative external references) --useSpecVersion Uses the version listed in the \`info.version\` field in the API definition for the project version parameter. + --workingDirectory string Working directory (for usage with relative external references) -h, --help Display this usage guide Related commands @@ -42,9 +42,9 @@ Options uploading an existing API definition. --version string Project version. If running command in a CI environment and this option is not passed, the main project version will be used. - --workingDirectory string Working directory (for usage with relative external references) --useSpecVersion Uses the version listed in the \`info.version\` field in the API definition for the project version parameter. + --workingDirectory string Working directory (for usage with relative external references) -h, --help Display this usage guide Related commands @@ -69,9 +69,9 @@ Options uploading an existing API definition. --version string Project version. If running command in a CI environment and this option is not passed, the main project version will be used. - --workingDirectory string Working directory (for usage with relative external references) --useSpecVersion Uses the version listed in the \`info.version\` field in the API definition for the project version parameter. + --workingDirectory string Working directory (for usage with relative external references) -h, --help Display this usage guide Related commands diff --git a/src/cmds/openapi.js b/src/cmds/openapi.js index 4cee6887b..a27ccc9ee 100644 --- a/src/cmds/openapi.js +++ b/src/cmds/openapi.js @@ -41,17 +41,17 @@ module.exports = class OpenAPICommand { type: String, defaultOption: true, }, - { - name: 'workingDirectory', - type: String, - description: 'Working directory (for usage with relative external references)', - }, { name: 'useSpecVersion', type: Boolean, description: 'Uses the version listed in the `info.version` field in the API definition for the project version parameter.', }, + { + name: 'workingDirectory', + type: String, + description: 'Working directory (for usage with relative external references)', + }, ]; } From 6925bd48d0c725bdb938de874ccb62b445bf8465 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 8 Aug 2022 18:57:06 -0500 Subject: [PATCH 12/20] chore: use info statement instead of debug --- src/cmds/openapi.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cmds/openapi.js b/src/cmds/openapi.js index a27ccc9ee..bceea3201 100644 --- a/src/cmds/openapi.js +++ b/src/cmds/openapi.js @@ -2,7 +2,7 @@ const APIError = require('../lib/apiError'); const chalk = require('chalk'); const { cleanHeaders } = require('../lib/fetch'); const config = require('config'); -const { debug, warn, oraOptions } = require('../lib/logger'); +const { debug, info, warn, oraOptions } = require('../lib/logger'); const fetch = require('../lib/fetch'); const { handleRes } = require('../lib/fetch'); const { getProjectVersion } = require('../lib/versionSelect'); @@ -81,7 +81,7 @@ module.exports = class OpenAPICommand { const { bundledSpec, specPath, specType, specVersion } = await prepareOas(spec, 'openapi'); if (useSpecVersion) { - debug(`using spec version: ${specVersion}`); + info(`Using the version specified in your API definition for your ReadMe project version (${specVersion})`); selectedVersion = specVersion; } From bfba67161c4c85fe36df2142e535a2dd7eea9041 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 8 Aug 2022 19:05:03 -0500 Subject: [PATCH 13/20] chore: use info emoji in logger --- src/lib/logger.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/logger.js b/src/lib/logger.js index 6b888f10a..e0de6b4cd 100644 --- a/src/lib/logger.js +++ b/src/lib/logger.js @@ -33,7 +33,7 @@ module.exports.info = function info(input) { /* istanbul ignore next */ if (isGHA() && process.env.NODE_ENV !== 'testing') return core.notice(input); // eslint-disable-next-line no-console - return console.info(input); + return console.info(`ℹ️ ${input}`); }; module.exports.oraOptions = function oraOptions() { From ab9c95664209b8ddaa4e0ffbff3ad06007303d3c Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Mon, 8 Aug 2022 19:08:51 -0500 Subject: [PATCH 14/20] test: fix tests this should have been a separate PR lol sorry --- __tests__/cmds/docs.test.js | 2 +- __tests__/cmds/openapi.test.js | 2 +- __tests__/cmds/validate.test.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/__tests__/cmds/docs.test.js b/__tests__/cmds/docs.test.js index fd2cb3640..c4b57d4b1 100644 --- a/__tests__/cmds/docs.test.js +++ b/__tests__/cmds/docs.test.js @@ -473,7 +473,7 @@ describe('rdme docs:edit', () => { versionMock.done(); expect(fs.existsSync(`${slug}.md`)).toBe(false); - expect(console.info).toHaveBeenCalledWith('Doc successfully updated. Cleaning up local file.'); + expect(console.info).toHaveBeenCalledWith('ℹ️ Doc successfully updated. Cleaning up local file.'); return console.info.mockRestore(); }); diff --git a/__tests__/cmds/openapi.test.js b/__tests__/cmds/openapi.test.js index d8bcb3e5d..c6cb8e9d3 100644 --- a/__tests__/cmds/openapi.test.js +++ b/__tests__/cmds/openapi.test.js @@ -132,7 +132,7 @@ describe('rdme openapi', () => { expect(console.info).toHaveBeenCalledTimes(1); const output = getCommandOutput(); - expect(output).toBe(chalk.yellow('We found swagger.json and are attempting to upload it.')); + expect(output).toBe(chalk.yellow('ℹ️ We found swagger.json and are attempting to upload it.')); fs.unlinkSync('./swagger.json'); return mock.done(); diff --git a/__tests__/cmds/validate.test.js b/__tests__/cmds/validate.test.js index 9218ff9d3..f969863c8 100644 --- a/__tests__/cmds/validate.test.js +++ b/__tests__/cmds/validate.test.js @@ -51,7 +51,7 @@ describe('rdme validate', () => { expect(console.info).toHaveBeenCalledTimes(1); const output = getCommandOutput(); - expect(output).toBe(chalk.yellow('We found swagger.json and are attempting to validate it.')); + expect(output).toBe(chalk.yellow('ℹ️ We found swagger.json and are attempting to validate it.')); fs.unlinkSync('./swagger.json'); }); From ae493f1544a5b58a13e21bf4952bcdfba8aff638 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 9 Aug 2022 17:32:07 -0500 Subject: [PATCH 15/20] fix: import paths for versionOpt wtf VSCode... --- src/cmds/categories/create.ts | 2 +- src/cmds/categories/index.ts | 2 +- src/cmds/docs/edit.ts | 2 +- src/cmds/docs/index.ts | 2 +- src/cmds/docs/single.ts | 2 +- src/cmds/openapi.ts | 3 +-- src/cmds/versions/update.ts | 2 +- 7 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/cmds/categories/create.ts b/src/cmds/categories/create.ts index e8836a2ac..241beafae 100644 --- a/src/cmds/categories/create.ts +++ b/src/cmds/categories/create.ts @@ -4,7 +4,7 @@ import chalk from 'chalk'; import config from 'config'; import { Headers } from 'node-fetch'; -import versionOpt from 'lib/versionOpt'; +import versionOpt from '../../lib/versionOpt'; import Command, { CommandCategories } from '../../lib/baseCommand'; import fetch, { cleanHeaders, handleRes } from '../../lib/fetch'; diff --git a/src/cmds/categories/index.ts b/src/cmds/categories/index.ts index 49148304a..4ee9a3a93 100644 --- a/src/cmds/categories/index.ts +++ b/src/cmds/categories/index.ts @@ -1,6 +1,6 @@ import type { CommandOptions } from '../../lib/baseCommand'; -import versionOpt from 'lib/versionOpt'; +import versionOpt from '../../lib/versionOpt'; import Command, { CommandCategories } from '../../lib/baseCommand'; import getCategories from '../../lib/getCategories'; diff --git a/src/cmds/docs/edit.ts b/src/cmds/docs/edit.ts index 7d6c69e5f..1cf26602c 100644 --- a/src/cmds/docs/edit.ts +++ b/src/cmds/docs/edit.ts @@ -7,7 +7,7 @@ import config from 'config'; import { Headers } from 'node-fetch'; import editor from 'editor'; -import versionOpt from 'lib/versionOpt'; +import versionOpt from '../../lib/versionOpt'; import APIError from '../../lib/apiError'; import Command, { CommandCategories } from '../../lib/baseCommand'; diff --git a/src/cmds/docs/index.ts b/src/cmds/docs/index.ts index c9d79a562..a3521e642 100644 --- a/src/cmds/docs/index.ts +++ b/src/cmds/docs/index.ts @@ -3,7 +3,7 @@ import type { CommandOptions } from '../../lib/baseCommand'; import chalk from 'chalk'; import config from 'config'; -import versionOpt from 'lib/versionOpt'; +import versionOpt from '../../lib/versionOpt'; import Command, { CommandCategories } from '../../lib/baseCommand'; import { debug } from '../../lib/logger'; diff --git a/src/cmds/docs/single.ts b/src/cmds/docs/single.ts index 0a58584a9..42405355f 100644 --- a/src/cmds/docs/single.ts +++ b/src/cmds/docs/single.ts @@ -3,7 +3,7 @@ import type { CommandOptions } from '../../lib/baseCommand'; import chalk from 'chalk'; import config from 'config'; -import versionOpt from 'lib/versionOpt'; +import versionOpt from '../../lib/versionOpt'; import Command, { CommandCategories } from '../../lib/baseCommand'; import { debug } from '../../lib/logger'; diff --git a/src/cmds/openapi.ts b/src/cmds/openapi.ts index ced6f3f3e..a222cd8f2 100644 --- a/src/cmds/openapi.ts +++ b/src/cmds/openapi.ts @@ -8,14 +8,13 @@ import { Headers } from 'node-fetch'; import ora from 'ora'; import parse from 'parse-link-header'; -import versionOpt from 'lib/versionOpt'; - import Command, { CommandCategories } from '../lib/baseCommand'; import fetch, { cleanHeaders, handleRes } from '../lib/fetch'; import { debug, info, warn, oraOptions } from '../lib/logger'; import prepareOas from '../lib/prepareOas'; import * as promptHandler from '../lib/prompts'; import streamSpecToRegistry from '../lib/streamSpecToRegistry'; +import versionOpt from '../lib/versionOpt'; import { getProjectVersion } from '../lib/versionSelect'; export type Options = { diff --git a/src/cmds/versions/update.ts b/src/cmds/versions/update.ts index 9ddbd7887..2c87d1c04 100644 --- a/src/cmds/versions/update.ts +++ b/src/cmds/versions/update.ts @@ -4,7 +4,7 @@ import config from 'config'; import { prompt } from 'enquirer'; import { Headers } from 'node-fetch'; -import versionOpt from 'lib/versionOpt'; +import versionOpt from '../../lib/versionOpt'; import Command, { CommandCategories } from '../../lib/baseCommand'; import fetch, { cleanHeaders, handleRes } from '../../lib/fetch'; From f979f5bb70bed424fafcfa8062c7f23eaa61b88b Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 9 Aug 2022 17:32:48 -0500 Subject: [PATCH 16/20] fix: some merge issues --- src/cmds/openapi.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/cmds/openapi.ts b/src/cmds/openapi.ts index a222cd8f2..8dd990464 100644 --- a/src/cmds/openapi.ts +++ b/src/cmds/openapi.ts @@ -77,7 +77,7 @@ export default class OpenAPICommand extends Command { return Promise.reject(new Error('No project API key provided. Please use `--key`.')); } - let selectedVersion: string; + let selectedVersion = version; let isUpdate: boolean; const spinner = ora({ ...oraOptions() }); @@ -89,10 +89,6 @@ export default class OpenAPICommand extends Command { warn("We'll be using the version associated with the `--id` option, so the `--version` option will be ignored."); } - if (!key) { - return Promise.reject(new Error('No project API key provided. Please use `--key`.')); - } - // Reason we're hardcoding in command here is because `swagger` command // relies on this and we don't want to use `swagger` in this function const { bundledSpec, specPath, specType, specVersion } = await prepareOas(spec, 'openapi'); From 07cddf9700fd01116c0606d04624ff06083b1e81 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 9 Aug 2022 17:34:08 -0500 Subject: [PATCH 17/20] fix: lint --- src/cmds/categories/create.ts | 3 +-- src/cmds/categories/index.ts | 3 +-- src/cmds/docs/edit.ts | 2 +- src/cmds/docs/index.ts | 3 +-- src/cmds/docs/single.ts | 3 +-- src/cmds/versions/update.ts | 3 +-- 6 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/cmds/categories/create.ts b/src/cmds/categories/create.ts index 241beafae..d7c7a7d8f 100644 --- a/src/cmds/categories/create.ts +++ b/src/cmds/categories/create.ts @@ -4,12 +4,11 @@ import chalk from 'chalk'; import config from 'config'; import { Headers } from 'node-fetch'; -import versionOpt from '../../lib/versionOpt'; - import Command, { CommandCategories } from '../../lib/baseCommand'; import fetch, { cleanHeaders, handleRes } from '../../lib/fetch'; import getCategories from '../../lib/getCategories'; import { debug } from '../../lib/logger'; +import versionOpt from '../../lib/versionOpt'; import { getProjectVersion } from '../../lib/versionSelect'; interface Category { diff --git a/src/cmds/categories/index.ts b/src/cmds/categories/index.ts index 4ee9a3a93..5367ee0aa 100644 --- a/src/cmds/categories/index.ts +++ b/src/cmds/categories/index.ts @@ -1,10 +1,9 @@ import type { CommandOptions } from '../../lib/baseCommand'; -import versionOpt from '../../lib/versionOpt'; - import Command, { CommandCategories } from '../../lib/baseCommand'; import getCategories from '../../lib/getCategories'; import { debug } from '../../lib/logger'; +import versionOpt from '../../lib/versionOpt'; import { getProjectVersion } from '../../lib/versionSelect'; export default class CategoriesCommand extends Command { diff --git a/src/cmds/docs/edit.ts b/src/cmds/docs/edit.ts index 1cf26602c..a91acfc69 100644 --- a/src/cmds/docs/edit.ts +++ b/src/cmds/docs/edit.ts @@ -7,12 +7,12 @@ import config from 'config'; import { Headers } from 'node-fetch'; import editor from 'editor'; -import versionOpt from '../../lib/versionOpt'; import APIError from '../../lib/apiError'; import Command, { CommandCategories } from '../../lib/baseCommand'; import fetch, { cleanHeaders, handleRes } from '../../lib/fetch'; import { debug, info } from '../../lib/logger'; +import versionOpt from '../../lib/versionOpt'; import { getProjectVersion } from '../../lib/versionSelect'; const writeFile = promisify(fs.writeFile); diff --git a/src/cmds/docs/index.ts b/src/cmds/docs/index.ts index a3521e642..7290a3792 100644 --- a/src/cmds/docs/index.ts +++ b/src/cmds/docs/index.ts @@ -3,11 +3,10 @@ import type { CommandOptions } from '../../lib/baseCommand'; import chalk from 'chalk'; import config from 'config'; -import versionOpt from '../../lib/versionOpt'; - import Command, { CommandCategories } from '../../lib/baseCommand'; import { debug } from '../../lib/logger'; import pushDoc, { readdirRecursive } from '../../lib/pushDoc'; +import versionOpt from '../../lib/versionOpt'; import { getProjectVersion } from '../../lib/versionSelect'; export type Options = { diff --git a/src/cmds/docs/single.ts b/src/cmds/docs/single.ts index 42405355f..b0a3fcbb9 100644 --- a/src/cmds/docs/single.ts +++ b/src/cmds/docs/single.ts @@ -3,11 +3,10 @@ import type { CommandOptions } from '../../lib/baseCommand'; import chalk from 'chalk'; import config from 'config'; -import versionOpt from '../../lib/versionOpt'; - import Command, { CommandCategories } from '../../lib/baseCommand'; import { debug } from '../../lib/logger'; import pushDoc from '../../lib/pushDoc'; +import versionOpt from '../../lib/versionOpt'; import { getProjectVersion } from '../../lib/versionSelect'; export type Options = { diff --git a/src/cmds/versions/update.ts b/src/cmds/versions/update.ts index 2c87d1c04..365e78eed 100644 --- a/src/cmds/versions/update.ts +++ b/src/cmds/versions/update.ts @@ -4,12 +4,11 @@ import config from 'config'; import { prompt } from 'enquirer'; import { Headers } from 'node-fetch'; -import versionOpt from '../../lib/versionOpt'; - import Command, { CommandCategories } from '../../lib/baseCommand'; import fetch, { cleanHeaders, handleRes } from '../../lib/fetch'; import { debug } from '../../lib/logger'; import * as promptHandler from '../../lib/prompts'; +import versionOpt from '../../lib/versionOpt'; import { getProjectVersion } from '../../lib/versionSelect'; export type Options = { From 26d9f9fa0692f27e2ecb61bfb80c39e879ac9752 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 9 Aug 2022 17:37:00 -0500 Subject: [PATCH 18/20] test: fix one more test jeez --- __tests__/cmds/docs/edit.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/__tests__/cmds/docs/edit.test.ts b/__tests__/cmds/docs/edit.test.ts index 48660095f..f742620ca 100644 --- a/__tests__/cmds/docs/edit.test.ts +++ b/__tests__/cmds/docs/edit.test.ts @@ -58,7 +58,7 @@ describe('rdme docs:edit', () => { expect(fs.existsSync(`${slug}.md`)).toBe(false); // eslint-disable-next-line no-console - expect(console.info).toHaveBeenCalledWith('Doc successfully updated. Cleaning up local file.'); + expect(console.info).toHaveBeenCalledWith('ℹ️ Doc successfully updated. Cleaning up local file.'); consoleSpy.mockRestore(); }); From 695438b487b72eb12c66344c2f65950d01c455e6 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 9 Aug 2022 18:19:53 -0500 Subject: [PATCH 19/20] fix: trailing period Co-Authored-By: Jon Ursenbach --- __tests__/__snapshots__/index.test.ts.snap | 2 +- __tests__/lib/commands.test.ts | 2 +- src/cmds/versions/index.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/__tests__/__snapshots__/index.test.ts.snap b/__tests__/__snapshots__/index.test.ts.snap index c26f0fa02..82a616f5c 100644 --- a/__tests__/__snapshots__/index.test.ts.snap +++ b/__tests__/__snapshots__/index.test.ts.snap @@ -92,7 +92,7 @@ Usage Options --key string Project API key - --version string A specific project version to view + --version string A specific project version to view. --raw Return raw output from the API instead of in a \\"pretty\\" format. -h, --help Display this usage guide diff --git a/__tests__/lib/commands.test.ts b/__tests__/lib/commands.test.ts index adf0d4926..6f3901bf7 100644 --- a/__tests__/lib/commands.test.ts +++ b/__tests__/lib/commands.test.ts @@ -58,7 +58,7 @@ describe('utils', () => { expect(arg.description).toBe( command.command !== 'versions' ? 'Project version. If running command in a CI environment and this option is not passed, the main project version will be used.' - : 'A specific project version to view' + : 'A specific project version to view.' ); } }); diff --git a/src/cmds/versions/index.ts b/src/cmds/versions/index.ts index e25aa97d2..ffc3bb4da 100644 --- a/src/cmds/versions/index.ts +++ b/src/cmds/versions/index.ts @@ -43,7 +43,7 @@ export default class VersionsCommand extends Command { { name: 'version', type: String, - description: 'A specific project version to view', + description: 'A specific project version to view.', }, { name: 'raw', From ab3fad6a4275404aa362e5750a659d1f318f8dce Mon Sep 17 00:00:00 2001 From: Jon Ursenbach Date: Tue, 9 Aug 2022 16:42:36 -0700 Subject: [PATCH 20/20] fix: version arg refactors --- src/cmds/categories/create.ts | 3 +-- src/cmds/categories/index.ts | 3 +-- src/cmds/docs/edit.ts | 3 +-- src/cmds/docs/index.ts | 3 +-- src/cmds/docs/single.ts | 3 +-- src/cmds/openapi.ts | 3 +-- src/cmds/versions/update.ts | 3 +-- src/lib/baseCommand.ts | 10 ++++++++++ src/lib/versionOpt.js | 6 ------ 9 files changed, 17 insertions(+), 20 deletions(-) delete mode 100644 src/lib/versionOpt.js diff --git a/src/cmds/categories/create.ts b/src/cmds/categories/create.ts index b7a7235c5..735ee463a 100644 --- a/src/cmds/categories/create.ts +++ b/src/cmds/categories/create.ts @@ -8,7 +8,6 @@ import Command, { CommandCategories } from '../../lib/baseCommand'; import fetch, { cleanHeaders, handleRes } from '../../lib/fetch'; import getCategories from '../../lib/getCategories'; import { debug } from '../../lib/logger'; -import versionOpt from '../../lib/versionOpt'; import { getProjectVersion } from '../../lib/versionSelect'; interface Category { @@ -39,7 +38,7 @@ export default class CategoriesCreateCommand extends Command { type: String, description: 'Project API key', }, - versionOpt, + this.getVersionArg(), { name: 'title', type: String, diff --git a/src/cmds/categories/index.ts b/src/cmds/categories/index.ts index acd2fe390..c2acde7b2 100644 --- a/src/cmds/categories/index.ts +++ b/src/cmds/categories/index.ts @@ -3,7 +3,6 @@ import type { CommandOptions } from '../../lib/baseCommand'; import Command, { CommandCategories } from '../../lib/baseCommand'; import getCategories from '../../lib/getCategories'; import { debug } from '../../lib/logger'; -import versionOpt from '../../lib/versionOpt'; import { getProjectVersion } from '../../lib/versionSelect'; export default class CategoriesCommand extends Command { @@ -22,7 +21,7 @@ export default class CategoriesCommand extends Command { type: String, description: 'Project API key', }, - versionOpt, + this.getVersionArg(), ]; } diff --git a/src/cmds/docs/edit.ts b/src/cmds/docs/edit.ts index 0a49e5f48..33b6eb308 100644 --- a/src/cmds/docs/edit.ts +++ b/src/cmds/docs/edit.ts @@ -12,7 +12,6 @@ import APIError from '../../lib/apiError'; import Command, { CommandCategories } from '../../lib/baseCommand'; import fetch, { cleanHeaders, handleRes } from '../../lib/fetch'; import { debug, info } from '../../lib/logger'; -import versionOpt from '../../lib/versionOpt'; import { getProjectVersion } from '../../lib/versionSelect'; const writeFile = promisify(fs.writeFile); @@ -41,7 +40,7 @@ export default class EditDocsCommand extends Command { type: String, description: 'Project API key', }, - versionOpt, + this.getVersionArg(), { name: 'slug', type: String, diff --git a/src/cmds/docs/index.ts b/src/cmds/docs/index.ts index 9ef810f6f..40fca8b51 100644 --- a/src/cmds/docs/index.ts +++ b/src/cmds/docs/index.ts @@ -6,7 +6,6 @@ import config from 'config'; import Command, { CommandCategories } from '../../lib/baseCommand'; import { debug } from '../../lib/logger'; import pushDoc, { readdirRecursive } from '../../lib/pushDoc'; -import versionOpt from '../../lib/versionOpt'; import { getProjectVersion } from '../../lib/versionSelect'; export type Options = { @@ -31,7 +30,7 @@ export default class DocsCommand extends Command { type: String, description: 'Project API key', }, - versionOpt, + this.getVersionArg(), { name: 'folder', type: String, diff --git a/src/cmds/docs/single.ts b/src/cmds/docs/single.ts index 464d55591..eb80c5cb8 100644 --- a/src/cmds/docs/single.ts +++ b/src/cmds/docs/single.ts @@ -6,7 +6,6 @@ import config from 'config'; import Command, { CommandCategories } from '../../lib/baseCommand'; import { debug } from '../../lib/logger'; import pushDoc from '../../lib/pushDoc'; -import versionOpt from '../../lib/versionOpt'; import { getProjectVersion } from '../../lib/versionSelect'; export type Options = { @@ -31,7 +30,7 @@ export default class SingleDocCommand extends Command { type: String, description: 'Project API key', }, - versionOpt, + this.getVersionArg(), { name: 'filePath', type: String, diff --git a/src/cmds/openapi.ts b/src/cmds/openapi.ts index ff2f122e7..2a65f56d3 100644 --- a/src/cmds/openapi.ts +++ b/src/cmds/openapi.ts @@ -14,7 +14,6 @@ import { debug, info, warn, oraOptions } from '../lib/logger'; import prepareOas from '../lib/prepareOas'; import * as promptHandler from '../lib/prompts'; import streamSpecToRegistry from '../lib/streamSpecToRegistry'; -import versionOpt from '../lib/versionOpt'; import { getProjectVersion } from '../lib/versionSelect'; export type Options = { @@ -48,7 +47,7 @@ export default class OpenAPICommand extends Command { description: "Unique identifier for your API definition. Use this if you're re-uploading an existing API definition.", }, - versionOpt, + this.getVersionArg(), { name: 'spec', type: String, diff --git a/src/cmds/versions/update.ts b/src/cmds/versions/update.ts index 814d7b7f8..6848563ba 100644 --- a/src/cmds/versions/update.ts +++ b/src/cmds/versions/update.ts @@ -8,7 +8,6 @@ import Command, { CommandCategories } from '../../lib/baseCommand'; import fetch, { cleanHeaders, handleRes } from '../../lib/fetch'; import { debug } from '../../lib/logger'; import * as promptHandler from '../../lib/prompts'; -import versionOpt from '../../lib/versionOpt'; import { getProjectVersion } from '../../lib/versionSelect'; export type Options = { @@ -36,7 +35,7 @@ export default class UpdateVersionCommand extends Command { type: String, description: 'Project API key', }, - versionOpt, + this.getVersionArg(), { name: 'codename', type: String, diff --git a/src/lib/baseCommand.ts b/src/lib/baseCommand.ts index 8a48432b8..7c27b7ce9 100644 --- a/src/lib/baseCommand.ts +++ b/src/lib/baseCommand.ts @@ -43,4 +43,14 @@ export default class Command { } } } + + // eslint-disable-next-line class-methods-use-this + getVersionArg() { + return { + name: 'version', + type: String, + description: + 'Project version. If running command in a CI environment and this option is not passed, the main project version will be used.', + }; + } } diff --git a/src/lib/versionOpt.js b/src/lib/versionOpt.js deleted file mode 100644 index 461a2e523..000000000 --- a/src/lib/versionOpt.js +++ /dev/null @@ -1,6 +0,0 @@ -module.exports = { - name: 'version', - type: String, - description: - 'Project version. If running command in a CI environment and this option is not passed, the main project version will be used.', -};