From 0873fefa12c18fb5071b7c95cfb69301cb22bc94 Mon Sep 17 00:00:00 2001 From: Shai Lachmanovich Date: Tue, 23 Aug 2022 10:55:27 +0200 Subject: [PATCH 01/10] feat(openapi): Add `updateSingleSpec` option to automatically update an only available spec file without any prompts --- __tests__/cmds/openapi/index.test.ts | 32 ++++++++++++++++++++++++++++ src/cmds/openapi/index.ts | 13 ++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/__tests__/cmds/openapi/index.test.ts b/__tests__/cmds/openapi/index.test.ts index 1150246be..28e690daa 100644 --- a/__tests__/cmds/openapi/index.test.ts +++ b/__tests__/cmds/openapi/index.test.ts @@ -409,6 +409,38 @@ describe('rdme openapi', () => { return mock.done(); }); + it('should update a spec file without prompts if providing `updateSingleSpec` and it\'s the only spec available' , async () => { + const registryUUID = getRandomRegistryId(); + + const mock = getAPIMock() + .get(`/api/v1/version/${version}`) + .basicAuth({ user: key }) + .reply(200, [{ version }]) + .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) + .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }) + .get('/api/v1/api-specification') + .basicAuth({ user: key }) + .reply(200, [ + { _id: 'spec1', title: 'spec1_title' }, + ]) + .put('/api/v1/api-specification/spec1', { registryUUID }) + .delayConnection(1000) + .basicAuth({ user: key }) + .reply(201, { _id: 1 }, { location: exampleRefLocation }); + + const spec = './__tests__/__fixtures__/ref-oas/petstore.json'; + + await expect( + openapi.run({ + key, + version, + spec, + updateSingleSpec: true + }) + ).resolves.toBe(successfulUpdate(spec)); + return mock.done(); + }); + it.todo('should paginate to next and previous pages of specs'); }); diff --git a/src/cmds/openapi/index.ts b/src/cmds/openapi/index.ts index 4322bb6d0..6d9cc9a4f 100644 --- a/src/cmds/openapi/index.ts +++ b/src/cmds/openapi/index.ts @@ -23,6 +23,7 @@ export type Options = { create?: boolean; useSpecVersion?: boolean; workingDirectory?: string; + updateSingleSpec?: boolean; }; export default class OpenAPICommand extends Command { @@ -70,13 +71,18 @@ export default class OpenAPICommand extends Command { type: String, description: 'Working directory (for usage with relative external references)', }, + { + name: 'updateSingleSpec', + type: Boolean, + description: 'Automatically update an existing spec file if it\'s the only one found', + }, ]; } async run(opts: CommandOptions) { super.run(opts); - const { key, id, spec, create, useSpecVersion, version, workingDirectory } = opts; + const { key, id, spec, create, useSpecVersion, version, workingDirectory, updateSingleSpec } = opts; let selectedVersion = version; let isUpdate: boolean; @@ -239,6 +245,11 @@ export default class OpenAPICommand extends Command { Command.debug(`api settings list response payload: ${JSON.stringify(apiSettingsBody)}`); if (!apiSettingsBody.length) return createSpec(); + if (apiSettingsBody.length === 1 && updateSingleSpec) { + const {_id: specId} = apiSettingsBody[0]; + return updateSpec(specId); + } + // @todo: figure out how to add a stricter type here, see: // https://github.com/readmeio/rdme/pull/570#discussion_r949715913 const { option } = await promptTerminal( From 8d4402830e736201489a07430c5171da819cea7c Mon Sep 17 00:00:00 2001 From: Shai Lachmanovich Date: Tue, 23 Aug 2022 11:01:27 +0200 Subject: [PATCH 02/10] feat(docs): Updated docs --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 11a8999a2..84a17d71e 100644 --- a/README.md +++ b/README.md @@ -117,12 +117,14 @@ rdme openapi [path-to-file.json] --id={existing-id} #### Uploading or Editing an API Definition in a Project Version -You can additional include a version flag, specifying the target version for your file's destination. This approach will provide you with CLI prompts, so we do not recommend this technique in CI environments. +You can additionally include a version flag, specifying the target version for your file's destination. This approach will provide you with CLI prompts, so we do not recommend this technique in CI environments. ```sh rdme openapi [path-to-file.json] --version={project-version} ``` +You can add `--updateSingleSpec` to the command so if there's only one spec file available to update, it will select it without any prompts. + If you wish to use the version specified [in the `info.version` field of your API definition](https://spec.openapis.org/oas/v3.1.0#fixed-fields-0), you can pass the `--useSpecVersion` option. For example, say [the `info` object](https://spec.openapis.org/oas/v3.1.0#info-object) of your API definition looks like this: ```json From f0da91b00de4bb79ef52dbb62b164e1a4d941271 Mon Sep 17 00:00:00 2001 From: Shai Lachmanovich Date: Tue, 23 Aug 2022 15:27:44 +0200 Subject: [PATCH 03/10] Fix eslint errors --- __tests__/cmds/openapi/index.test.ts | 8 +++----- src/cmds/openapi/index.ts | 4 ++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/__tests__/cmds/openapi/index.test.ts b/__tests__/cmds/openapi/index.test.ts index 28e690daa..0d5c04e12 100644 --- a/__tests__/cmds/openapi/index.test.ts +++ b/__tests__/cmds/openapi/index.test.ts @@ -409,7 +409,7 @@ describe('rdme openapi', () => { return mock.done(); }); - it('should update a spec file without prompts if providing `updateSingleSpec` and it\'s the only spec available' , async () => { + it("should update a spec file without prompts if providing `updateSingleSpec` and it's the only spec available", async () => { const registryUUID = getRandomRegistryId(); const mock = getAPIMock() @@ -420,9 +420,7 @@ describe('rdme openapi', () => { .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }) .get('/api/v1/api-specification') .basicAuth({ user: key }) - .reply(200, [ - { _id: 'spec1', title: 'spec1_title' }, - ]) + .reply(200, [{ _id: 'spec1', title: 'spec1_title' }]) .put('/api/v1/api-specification/spec1', { registryUUID }) .delayConnection(1000) .basicAuth({ user: key }) @@ -435,7 +433,7 @@ describe('rdme openapi', () => { key, version, spec, - updateSingleSpec: true + updateSingleSpec: true, }) ).resolves.toBe(successfulUpdate(spec)); return mock.done(); diff --git a/src/cmds/openapi/index.ts b/src/cmds/openapi/index.ts index 6d9cc9a4f..67c2a55b8 100644 --- a/src/cmds/openapi/index.ts +++ b/src/cmds/openapi/index.ts @@ -74,7 +74,7 @@ export default class OpenAPICommand extends Command { { name: 'updateSingleSpec', type: Boolean, - description: 'Automatically update an existing spec file if it\'s the only one found', + description: "Automatically update an existing spec file if it's the only one found", }, ]; } @@ -246,7 +246,7 @@ export default class OpenAPICommand extends Command { if (!apiSettingsBody.length) return createSpec(); if (apiSettingsBody.length === 1 && updateSingleSpec) { - const {_id: specId} = apiSettingsBody[0]; + const { _id: specId } = apiSettingsBody[0]; return updateSpec(specId); } From 60e15130a690f86ba143f7eef62671e44dd5c723 Mon Sep 17 00:00:00 2001 From: Shai Lachmanovich Date: Tue, 23 Aug 2022 16:36:37 +0200 Subject: [PATCH 04/10] Throw error if using --updateSingleSpec when there are multiple spec files available --- __tests__/cmds/openapi/index.test.ts | 85 ++++++++++++++++++++-------- src/cmds/openapi/index.ts | 7 ++- 2 files changed, 66 insertions(+), 26 deletions(-) diff --git a/__tests__/cmds/openapi/index.test.ts b/__tests__/cmds/openapi/index.test.ts index 0d5c04e12..1eab13320 100644 --- a/__tests__/cmds/openapi/index.test.ts +++ b/__tests__/cmds/openapi/index.test.ts @@ -409,34 +409,69 @@ describe('rdme openapi', () => { return mock.done(); }); - it("should update a spec file without prompts if providing `updateSingleSpec` and it's the only spec available", async () => { - const registryUUID = getRandomRegistryId(); + describe('--updateSingleSpec', () => { + it("should update a spec file without prompts if providing `updateSingleSpec` and it's the only spec available", async () => { + const registryUUID = getRandomRegistryId(); - const mock = getAPIMock() - .get(`/api/v1/version/${version}`) - .basicAuth({ user: key }) - .reply(200, [{ version }]) - .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) - .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }) - .get('/api/v1/api-specification') - .basicAuth({ user: key }) - .reply(200, [{ _id: 'spec1', title: 'spec1_title' }]) - .put('/api/v1/api-specification/spec1', { registryUUID }) - .delayConnection(1000) - .basicAuth({ user: key }) - .reply(201, { _id: 1 }, { location: exampleRefLocation }); + const mock = getAPIMock() + .get(`/api/v1/version/${version}`) + .basicAuth({ user: key }) + .reply(200, [{ version }]) + .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) + .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }) + .get('/api/v1/api-specification') + .basicAuth({ user: key }) + .reply(200, [{ _id: 'spec1', title: 'spec1_title' }]) + .put('/api/v1/api-specification/spec1', { registryUUID }) + .delayConnection(1000) + .basicAuth({ user: key }) + .reply(201, { _id: 1 }, { location: exampleRefLocation }); - const spec = './__tests__/__fixtures__/ref-oas/petstore.json'; + const spec = './__tests__/__fixtures__/ref-oas/petstore.json'; - await expect( - openapi.run({ - key, - version, - spec, - updateSingleSpec: true, - }) - ).resolves.toBe(successfulUpdate(spec)); - return mock.done(); + await expect( + openapi.run({ + key, + version, + spec, + updateSingleSpec: true, + }) + ).resolves.toBe(successfulUpdate(spec)); + return mock.done(); + }); + + it('should error if providing `updateSingleSpec` and there are multiple specs available', async () => { + const registryUUID = getRandomRegistryId(); + + const mock = getAPIMock() + .get(`/api/v1/version/${version}`) + .basicAuth({ user: key }) + .reply(200, [{ version }]) + .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) + .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }) + .get('/api/v1/api-specification') + .basicAuth({ user: key }) + .reply(200, [ + { _id: 'spec1', title: 'spec1_title' }, + { _id: 'spec2', title: 'spec2_title' }, + ]); + + const spec = './__tests__/__fixtures__/ref-oas/petstore.json'; + + await expect( + openapi.run({ + key, + version, + spec, + updateSingleSpec: true, + }) + ).rejects.toStrictEqual( + new Error( + "The option `--updateSingleSpec` can't be used when there's more than one spec file available (found 2)." + ) + ); + return mock.done(); + }); }); it.todo('should paginate to next and previous pages of specs'); diff --git a/src/cmds/openapi/index.ts b/src/cmds/openapi/index.ts index 67c2a55b8..17509df53 100644 --- a/src/cmds/openapi/index.ts +++ b/src/cmds/openapi/index.ts @@ -245,7 +245,12 @@ export default class OpenAPICommand extends Command { Command.debug(`api settings list response payload: ${JSON.stringify(apiSettingsBody)}`); if (!apiSettingsBody.length) return createSpec(); - if (apiSettingsBody.length === 1 && updateSingleSpec) { + if (updateSingleSpec) { + if (apiSettingsBody.length > 1) { + throw new Error( + `The option \`--updateSingleSpec\` can't be used when there's more than one spec file available (found ${apiSettingsBody.length}).` + ); + } const { _id: specId } = apiSettingsBody[0]; return updateSpec(specId); } From 8e83532a95be1130c5f5a1fb655c03ee92cff5b1 Mon Sep 17 00:00:00 2001 From: Shai Lachmanovich Date: Tue, 23 Aug 2022 17:16:27 +0200 Subject: [PATCH 05/10] Show a warning when passing both `--updateSingleSpec` and `--id` --- __tests__/cmds/openapi/index.test.ts | 31 ++++++++++++++++++++++++++++ src/cmds/openapi/index.ts | 6 ++++++ 2 files changed, 37 insertions(+) diff --git a/__tests__/cmds/openapi/index.test.ts b/__tests__/cmds/openapi/index.test.ts index 1eab13320..8fd2aeed7 100644 --- a/__tests__/cmds/openapi/index.test.ts +++ b/__tests__/cmds/openapi/index.test.ts @@ -472,6 +472,37 @@ describe('rdme openapi', () => { ); return mock.done(); }); + + it('should warn if providing both `updateSingleSpec` and `id`', async () => { + const registryUUID = getRandomRegistryId(); + + const mock = getAPIMock() + .post('/api/v1/api-registry', body => body.match('form-data; name="spec"')) + .reply(201, { registryUUID, spec: { openapi: '3.0.0' } }) + .put('/api/v1/api-specification/spec1', { registryUUID }) + .delayConnection(1000) + .basicAuth({ user: key }) + .reply(201, { _id: 1 }, { location: exampleRefLocation }); + const spec = './__tests__/__fixtures__/ref-oas/petstore.json'; + + await expect( + openapi.run({ + key, + spec, + updateSingleSpec: true, + id: 'spec1', + }) + ).resolves.toBe(successfulUpdate(spec)); + + expect(console.warn).toHaveBeenCalledTimes(1); + expect(console.info).toHaveBeenCalledTimes(0); + + const output = getCommandOutput(); + expect(output).toMatch( + /When using the `--id` option the `--updateSingleSpec` option is ignored, as the desired spec id is already specified./ + ); + return mock.done(); + }); }); it.todo('should paginate to next and previous pages of specs'); diff --git a/src/cmds/openapi/index.ts b/src/cmds/openapi/index.ts index 17509df53..d76fbd438 100644 --- a/src/cmds/openapi/index.ts +++ b/src/cmds/openapi/index.ts @@ -102,6 +102,12 @@ export default class OpenAPICommand extends Command { Command.warn("We'll be using the `--create` option , so the `--id` parameter will be ignored."); } + if (updateSingleSpec && id) { + Command.warn( + 'When using the `--id` option the `--updateSingleSpec` option is ignored, as the desired spec id is already specified.' + ); + } + // 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 e1e9f920c9c8be681a1be9140efd1b83c1c73dd1 Mon Sep 17 00:00:00 2001 From: Shai Lachmanovich Date: Tue, 23 Aug 2022 17:17:35 +0200 Subject: [PATCH 06/10] Update tests snapshot --- __tests__/__snapshots__/index.test.ts.snap | 3 +++ 1 file changed, 3 insertions(+) diff --git a/__tests__/__snapshots__/index.test.ts.snap b/__tests__/__snapshots__/index.test.ts.snap index c15bd494d..9a3c6b259 100644 --- a/__tests__/__snapshots__/index.test.ts.snap +++ b/__tests__/__snapshots__/index.test.ts.snap @@ -19,6 +19,7 @@ Options --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) + --updateSingleSpec Automatically update an existing spec file if it's the only one found -h, --help Display this usage guide Related commands @@ -47,6 +48,7 @@ Options --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) + --updateSingleSpec Automatically update an existing spec file if it's the only one found -h, --help Display this usage guide Related commands @@ -75,6 +77,7 @@ Options --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) + --updateSingleSpec Automatically update an existing spec file if it's the only one found -h, --help Display this usage guide Related commands From b68e0ede4aaa67d087dbfdedb1caffdd1111bae8 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 23 Aug 2022 11:19:53 -0500 Subject: [PATCH 07/10] docs: copy edits, rename flag to `--update` --- README.md | 10 +++++++--- __tests__/__snapshots__/index.test.ts.snap | 9 ++++++--- __tests__/cmds/openapi/index.test.ts | 20 +++++++++----------- src/cmds/openapi/index.ts | 17 +++++++++-------- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 84a17d71e..3435632aa 100644 --- a/README.md +++ b/README.md @@ -109,7 +109,7 @@ rdme openapi [path-to-file.json] --version={project-version} --create #### Editing (Re-Syncing) an Existing API Definition -This will edit (re-sync) an existing API definition (identified by `--id`) within your ReadMe project. +This will edit (re-sync) an existing API definition (identified by `--id`) within your ReadMe project. **This is the recommended approach for usage in CI environments.** ```sh rdme openapi [path-to-file.json] --id={existing-id} @@ -123,8 +123,6 @@ You can additionally include a version flag, specifying the target version for y rdme openapi [path-to-file.json] --version={project-version} ``` -You can add `--updateSingleSpec` to the command so if there's only one spec file available to update, it will select it without any prompts. - If you wish to use the version specified [in the `info.version` field of your API definition](https://spec.openapis.org/oas/v3.1.0#fixed-fields-0), you can pass the `--useSpecVersion` option. For example, say [the `info` object](https://spec.openapis.org/oas/v3.1.0#info-object) of your API definition looks like this: ```json @@ -141,6 +139,12 @@ You can pass in the `--useSpecVersion` option, which would be equivalent to pass rdme openapi [path-to-file.json] --useSpecVersion ``` +You can add `--update` to the command so if there's only one API definition for the given project version to update, it will select it without any prompts: + +```sh +rdme openapi [path-to-file.json] --version={project-version} --update +``` + #### Omitting the File Path If you run `rdme` within a directory that contains your OpenAPI or Swagger definition, you can omit the file path. `rdme` will then look for JSON or YAML files (including in sub-directories) that contain a top-level [`openapi`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#fixed-fields) or [`swagger`](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/2.0.md#fixed-fields) property. diff --git a/__tests__/__snapshots__/index.test.ts.snap b/__tests__/__snapshots__/index.test.ts.snap index 9a3c6b259..4ee64a210 100644 --- a/__tests__/__snapshots__/index.test.ts.snap +++ b/__tests__/__snapshots__/index.test.ts.snap @@ -19,7 +19,8 @@ Options --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) - --updateSingleSpec Automatically update an existing spec file if it's the only one found + --update Automatically update an existing API definition in ReadMe if it's the + only one associated with the current version. -h, --help Display this usage guide Related commands @@ -48,7 +49,8 @@ Options --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) - --updateSingleSpec Automatically update an existing spec file if it's the only one found + --update Automatically update an existing API definition in ReadMe if it's the + only one associated with the current version. -h, --help Display this usage guide Related commands @@ -77,7 +79,8 @@ Options --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) - --updateSingleSpec Automatically update an existing spec file if it's the only one found + --update Automatically update an existing API definition in ReadMe if it's the + only one associated with the current version. -h, --help Display this usage guide Related commands diff --git a/__tests__/cmds/openapi/index.test.ts b/__tests__/cmds/openapi/index.test.ts index 8fd2aeed7..35625813e 100644 --- a/__tests__/cmds/openapi/index.test.ts +++ b/__tests__/cmds/openapi/index.test.ts @@ -409,8 +409,8 @@ describe('rdme openapi', () => { return mock.done(); }); - describe('--updateSingleSpec', () => { - it("should update a spec file without prompts if providing `updateSingleSpec` and it's the only spec available", async () => { + describe('--update', () => { + it("should update a spec file without prompts if providing `update` and it's the only spec available", async () => { const registryUUID = getRandomRegistryId(); const mock = getAPIMock() @@ -434,13 +434,13 @@ describe('rdme openapi', () => { key, version, spec, - updateSingleSpec: true, + update: true, }) ).resolves.toBe(successfulUpdate(spec)); return mock.done(); }); - it('should error if providing `updateSingleSpec` and there are multiple specs available', async () => { + it('should error if providing `update` and there are multiple specs available', async () => { const registryUUID = getRandomRegistryId(); const mock = getAPIMock() @@ -463,17 +463,17 @@ describe('rdme openapi', () => { key, version, spec, - updateSingleSpec: true, + update: true, }) ).rejects.toStrictEqual( new Error( - "The option `--updateSingleSpec` can't be used when there's more than one spec file available (found 2)." + "The `--update` option cannot be used when there's more than one API definition available (found 2)." ) ); return mock.done(); }); - it('should warn if providing both `updateSingleSpec` and `id`', async () => { + it('should warn if providing both `update` and `id`', async () => { const registryUUID = getRandomRegistryId(); const mock = getAPIMock() @@ -489,7 +489,7 @@ describe('rdme openapi', () => { openapi.run({ key, spec, - updateSingleSpec: true, + update: true, id: 'spec1', }) ).resolves.toBe(successfulUpdate(spec)); @@ -498,9 +498,7 @@ describe('rdme openapi', () => { expect(console.info).toHaveBeenCalledTimes(0); const output = getCommandOutput(); - expect(output).toMatch( - /When using the `--id` option the `--updateSingleSpec` option is ignored, as the desired spec id is already specified./ - ); + expect(output).toMatch(/the `--update` parameter will be ignored./); return mock.done(); }); }); diff --git a/src/cmds/openapi/index.ts b/src/cmds/openapi/index.ts index d76fbd438..2388b3be5 100644 --- a/src/cmds/openapi/index.ts +++ b/src/cmds/openapi/index.ts @@ -23,7 +23,7 @@ export type Options = { create?: boolean; useSpecVersion?: boolean; workingDirectory?: string; - updateSingleSpec?: boolean; + update?: boolean; }; export default class OpenAPICommand extends Command { @@ -72,9 +72,10 @@ export default class OpenAPICommand extends Command { description: 'Working directory (for usage with relative external references)', }, { - name: 'updateSingleSpec', + name: 'update', type: Boolean, - description: "Automatically update an existing spec file if it's the only one found", + description: + "Automatically update an existing API definition in ReadMe if it's the only one associated with the current version.", }, ]; } @@ -82,7 +83,7 @@ export default class OpenAPICommand extends Command { async run(opts: CommandOptions) { super.run(opts); - const { key, id, spec, create, useSpecVersion, version, workingDirectory, updateSingleSpec } = opts; + const { key, id, spec, create, useSpecVersion, version, workingDirectory, update } = opts; let selectedVersion = version; let isUpdate: boolean; @@ -102,9 +103,9 @@ export default class OpenAPICommand extends Command { Command.warn("We'll be using the `--create` option , so the `--id` parameter will be ignored."); } - if (updateSingleSpec && id) { + if (update && id) { Command.warn( - 'When using the `--id` option the `--updateSingleSpec` option is ignored, as the desired spec id is already specified.' + "We'll be updating the API definition associated with the `--id` parameter, so the `--update` parameter will be ignored." ); } @@ -251,10 +252,10 @@ export default class OpenAPICommand extends Command { Command.debug(`api settings list response payload: ${JSON.stringify(apiSettingsBody)}`); if (!apiSettingsBody.length) return createSpec(); - if (updateSingleSpec) { + if (update) { if (apiSettingsBody.length > 1) { throw new Error( - `The option \`--updateSingleSpec\` can't be used when there's more than one spec file available (found ${apiSettingsBody.length}).` + `The \`--update\` option cannot be used when there's more than one API definition available (found ${apiSettingsBody.length}).` ); } const { _id: specId } = apiSettingsBody[0]; From bba94482d2852eee9d5b3f4b1338ba9fde0ed990 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 23 Aug 2022 11:27:31 -0500 Subject: [PATCH 08/10] fix: add logic for if create and update flags passed together --- __tests__/cmds/openapi/index.test.ts | 6 ++++++ src/cmds/openapi/index.ts | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/__tests__/cmds/openapi/index.test.ts b/__tests__/cmds/openapi/index.test.ts index 35625813e..d31a79ff1 100644 --- a/__tests__/cmds/openapi/index.test.ts +++ b/__tests__/cmds/openapi/index.test.ts @@ -678,6 +678,12 @@ describe('rdme openapi', () => { ).rejects.toStrictEqual(new Error('No project API key provided. Please use `--key`.')); }); + it('should error if `--create` and `--update` flags are passed simultaneously', () => { + return expect(openapi.run({ key, create: true, update: true })).rejects.toStrictEqual( + new Error('The `--create` and `--update` options cannot be used simultaneously. Please use one or the other!') + ); + }); + it('should error if invalid API key is sent and version list does not load', async () => { const errorObject = { error: 'APIKEY_NOTFOUND', diff --git a/src/cmds/openapi/index.ts b/src/cmds/openapi/index.ts index 2388b3be5..da9e763c1 100644 --- a/src/cmds/openapi/index.ts +++ b/src/cmds/openapi/index.ts @@ -89,6 +89,12 @@ export default class OpenAPICommand extends Command { let isUpdate: boolean; const spinner = ora({ ...oraOptions() }); + if (create && update) { + throw new Error( + 'The `--create` and `--update` options cannot be used simultaneously. Please use one or the other!' + ); + } + if (workingDirectory) { process.chdir(workingDirectory); } From 95a8148b0ca7bd35dee541c92516e839809bd2e4 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 23 Aug 2022 12:18:29 -0500 Subject: [PATCH 09/10] ci: attempt to skip failing step if API key isn't present --- .github/workflows/ci.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index dd8470eff..c10d25232 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -80,5 +80,10 @@ jobs: # Docs: https://rdme-test.readme.io - name: Run `openapi` command uses: ./rdme-repo/ + # Only run this step if the GitHub secrets are present + # (this won't be the case for external contributors' forks) + # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idif + # https://docs.github.com/en/actions/learn-github-actions/expressions#about-expressions + if: ${{ secrets.RDME_TEST_PROJECT_API_KEY }} with: rdme: openapi oas-examples-repo/3.1/json/petstore.json --key=${{ secrets.RDME_TEST_PROJECT_API_KEY }} --id=${{ secrets.RDME_TEST_PROJECT_API_SETTING }} From 8ca159649a5b005737741824c27a89d9fd161079 Mon Sep 17 00:00:00 2001 From: Kanad Gupta Date: Tue, 23 Aug 2022 12:25:20 -0500 Subject: [PATCH 10/10] Revert "ci: attempt to skip failing step if API key isn't present" This reverts commit 95a8148b0ca7bd35dee541c92516e839809bd2e4. --- .github/workflows/ci.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c10d25232..dd8470eff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -80,10 +80,5 @@ jobs: # Docs: https://rdme-test.readme.io - name: Run `openapi` command uses: ./rdme-repo/ - # Only run this step if the GitHub secrets are present - # (this won't be the case for external contributors' forks) - # https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idif - # https://docs.github.com/en/actions/learn-github-actions/expressions#about-expressions - if: ${{ secrets.RDME_TEST_PROJECT_API_KEY }} with: rdme: openapi oas-examples-repo/3.1/json/petstore.json --key=${{ secrets.RDME_TEST_PROJECT_API_KEY }} --id=${{ secrets.RDME_TEST_PROJECT_API_SETTING }}