diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1c0886405..908cf2bde 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,10 +49,10 @@ jobs: path: oas-examples-repo repository: readmeio/oas-examples - - name: Run `validate` command + - name: Run `openapi:validate` command uses: ./rdme-repo/ with: - rdme: validate oas-examples-repo/3.1/json/petstore.json + rdme: openapi:validate oas-examples-repo/3.1/json/petstore.json # Docs: https://rdme-test.readme.io - name: Run `openapi` command diff --git a/.github/workflows/simple.yml b/.github/workflows/simple.yml index ae25074b9..bfccd1847 100644 --- a/.github/workflows/simple.yml +++ b/.github/workflows/simple.yml @@ -14,7 +14,7 @@ jobs: uses: actions/checkout@v3 # This is a simple example that runs our `validate` command on a local file. - - name: Run `validate` command + - name: Run `openapi:validate` command uses: ./ # in actual production usage, this value should be 'readmeio/rdme@XX' with: - rdme: validate __tests__/__fixtures__/ref-oas/petstore.json + rdme: openapi:validate __tests__/__fixtures__/ref-oas/petstore.json diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index ac88f86f7..c7f76a345 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,13 +6,13 @@ To run test commands from within the repository, run the build and then run your ```sh npm run build -./bin/rdme validate __tests__/__fixtures__/ref-oas/petstore.json +./bin/rdme openapi:validate __tests__/__fixtures__/ref-oas/petstore.json ``` If you need to debug commands quicker and re-building TS everytime is becoming cumbersome, you can use the debug command, like so: ```sh -npm run debug -- validate __tests__/__fixtures__/ref-oas/petstore.json +npm run debug -- openapi:validate __tests__/__fixtures__/ref-oas/petstore.json ``` ## Running GitHub Actions Locally 🐳 diff --git a/README.md b/README.md index 3435632aa..52be6d66e 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ npm install rdme --save-dev Once installed in your project, we recommend using `npx` (which is included if you have `npm` installed) to prefix all of your CLI commands. For example: ```sh -npx rdme validate [file] +npx rdme openapi:validate [file] ``` To ensure you're getting the latest features and security updates, we recommend using a tool like [Dependabot](https://docs.github.com/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/about-dependabot-version-updates) to keep `rdme` (and your other dependencies) up-to-date. @@ -175,7 +175,7 @@ rdme openapi petstore.json --workingDirectory=[path to directory] You can also perform a local validation of your API definition without uploading it to ReadMe, which can be useful when constructing or editing your API definition. ```sh -rdme validate [path-to-file.json] +rdme openapi:validate [path-to-file.json] ``` Similar to the `openapi` command, you can also [omit the file path](#omitting-the-file-path). diff --git a/__tests__/__snapshots__/index.test.ts.snap b/__tests__/__snapshots__/index.test.ts.snap index 63443fb5e..846852bb2 100644 --- a/__tests__/__snapshots__/index.test.ts.snap +++ b/__tests__/__snapshots__/index.test.ts.snap @@ -26,8 +26,8 @@ Options Related commands - $ rdme validate Validate your OpenAPI/Swagger definition. - $ rdme openapi:reduce Reduce an OpenAPI definition into a smaller subset. + $ rdme openapi:reduce Reduce an OpenAPI definition into a smaller subset. + $ rdme openapi:validate Validate your OpenAPI/Swagger definition. " `; @@ -57,8 +57,8 @@ Options Related commands - $ rdme validate Validate your OpenAPI/Swagger definition. - $ rdme openapi:reduce Reduce an OpenAPI definition into a smaller subset. + $ rdme openapi:reduce Reduce an OpenAPI definition into a smaller subset. + $ rdme openapi:validate Validate your OpenAPI/Swagger definition. " `; @@ -88,8 +88,8 @@ Options Related commands - $ rdme validate Validate your OpenAPI/Swagger definition. - $ rdme openapi:reduce Reduce an OpenAPI definition into a smaller subset. + $ rdme openapi:reduce Reduce an OpenAPI definition into a smaller subset. + $ rdme openapi:validate Validate your OpenAPI/Swagger definition. " `; diff --git a/__tests__/cmds/__snapshots__/validate.test.ts.snap b/__tests__/cmds/openapi/__snapshots__/validate.test.ts.snap similarity index 69% rename from __tests__/cmds/__snapshots__/validate.test.ts.snap rename to __tests__/cmds/openapi/__snapshots__/validate.test.ts.snap index 5baa9f32d..51c0ffc8b 100644 --- a/__tests__/cmds/__snapshots__/validate.test.ts.snap +++ b/__tests__/cmds/openapi/__snapshots__/validate.test.ts.snap @@ -1,6 +1,6 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`rdme validate GHA onboarding E2E tests should create GHA workflow if user passes in spec via opt (github flag enabled) 1`] = ` +exports[`rdme openapi:validate GHA onboarding E2E tests should create GHA workflow if user passes in spec via opt (github flag enabled) 1`] = ` " Your GitHub Actions workflow file has been created! ✨ @@ -10,7 +10,7 @@ Almost done! Push your newly created file (.github/workflows/validate-test-opt-s " `; -exports[`rdme validate GHA onboarding E2E tests should create GHA workflow if user passes in spec via opt (github flag enabled) 2`] = ` +exports[`rdme openapi:validate GHA onboarding E2E tests should create GHA workflow if user passes in spec via opt (github flag enabled) 2`] = ` "# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z # You can view our full documentation here: https://docs.readme.com/docs/rdme name: ReadMe GitHub Action 🦉 @@ -24,20 +24,20 @@ on: - validate-test-opt-spec-github-branch jobs: - rdme-validate: + rdme-openapi-validate: runs-on: ubuntu-latest steps: - name: Check out repo 📚 uses: actions/checkout@v3 - - name: Run \`validate\` command 🚀 + - name: Run \`openapi:validate\` command 🚀 uses: readmeio/rdme@7.8.9 with: - rdme: validate __tests__/__fixtures__/petstore-simple-weird-version.json + rdme: openapi:validate __tests__/__fixtures__/petstore-simple-weird-version.json " `; -exports[`rdme validate GHA onboarding E2E tests should create GHA workflow if user passes in spec via opt (including workingDirectory) 1`] = ` +exports[`rdme openapi:validate GHA onboarding E2E tests should create GHA workflow if user passes in spec via opt (including workingDirectory) 1`] = ` " Your GitHub Actions workflow file has been created! ✨ @@ -47,7 +47,7 @@ Almost done! Push your newly created file (.github/workflows/validate-test-opt-s " `; -exports[`rdme validate GHA onboarding E2E tests should create GHA workflow if user passes in spec via opt (including workingDirectory) 2`] = ` +exports[`rdme openapi:validate GHA onboarding E2E tests should create GHA workflow if user passes in spec via opt (including workingDirectory) 2`] = ` "# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z # You can view our full documentation here: https://docs.readme.com/docs/rdme name: ReadMe GitHub Action 🦉 @@ -61,20 +61,20 @@ on: - validate-test-opt-spec-github-branch jobs: - rdme-validate: + rdme-openapi-validate: runs-on: ubuntu-latest steps: - name: Check out repo 📚 uses: actions/checkout@v3 - - name: Run \`validate\` command 🚀 + - name: Run \`openapi:validate\` command 🚀 uses: readmeio/rdme@7.8.9 with: - rdme: validate petstore.json --workingDirectory=./__tests__/__fixtures__/relative-ref-oas + rdme: openapi:validate petstore.json --workingDirectory=./__tests__/__fixtures__/relative-ref-oas " `; -exports[`rdme validate GHA onboarding E2E tests should create GHA workflow if user passes in spec via opt 1`] = ` +exports[`rdme openapi:validate GHA onboarding E2E tests should create GHA workflow if user passes in spec via opt 1`] = ` " Your GitHub Actions workflow file has been created! ✨ @@ -84,7 +84,7 @@ Almost done! Push your newly created file (.github/workflows/validate-test-opt-s " `; -exports[`rdme validate GHA onboarding E2E tests should create GHA workflow if user passes in spec via opt 2`] = ` +exports[`rdme openapi:validate GHA onboarding E2E tests should create GHA workflow if user passes in spec via opt 2`] = ` "# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z # You can view our full documentation here: https://docs.readme.com/docs/rdme name: ReadMe GitHub Action 🦉 @@ -98,20 +98,20 @@ on: - validate-test-opt-spec-branch jobs: - rdme-validate: + rdme-openapi-validate: runs-on: ubuntu-latest steps: - name: Check out repo 📚 uses: actions/checkout@v3 - - name: Run \`validate\` command 🚀 + - name: Run \`openapi:validate\` command 🚀 uses: readmeio/rdme@7.8.9 with: - rdme: validate __tests__/__fixtures__/petstore-simple-weird-version.json + rdme: openapi:validate __tests__/__fixtures__/petstore-simple-weird-version.json " `; -exports[`rdme validate GHA onboarding E2E tests should create GHA workflow if user passes in spec via prompts 1`] = ` +exports[`rdme openapi:validate GHA onboarding E2E tests should create GHA workflow if user passes in spec via prompts 1`] = ` " Your GitHub Actions workflow file has been created! ✨ @@ -121,7 +121,7 @@ Almost done! Push your newly created file (.github/workflows/validate-test-file. " `; -exports[`rdme validate GHA onboarding E2E tests should create GHA workflow if user passes in spec via prompts 2`] = ` +exports[`rdme openapi:validate GHA onboarding E2E tests should create GHA workflow if user passes in spec via prompts 2`] = ` "# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z # You can view our full documentation here: https://docs.readme.com/docs/rdme name: ReadMe GitHub Action 🦉 @@ -135,20 +135,20 @@ on: - validate-test-branch jobs: - rdme-validate: + rdme-openapi-validate: runs-on: ubuntu-latest steps: - name: Check out repo 📚 uses: actions/checkout@v3 - - name: Run \`validate\` command 🚀 + - name: Run \`openapi:validate\` command 🚀 uses: readmeio/rdme@7.8.9 with: - rdme: validate __tests__/__fixtures__/petstore-simple-weird-version.json + rdme: openapi:validate __tests__/__fixtures__/petstore-simple-weird-version.json " `; -exports[`rdme validate error handling should throw an error if an invalid OpenAPI 3.1 definition is supplied 1`] = ` +exports[`rdme openapi:validate error handling should throw an error if an invalid OpenAPI 3.1 definition is supplied 1`] = ` [SyntaxError: OpenAPI schema validation failed. REQUIRED must have required property 'name' @@ -162,7 +162,7 @@ REQUIRED must have required property 'name' 29 | }] `; -exports[`rdme validate error handling should throw an error if an invalid Swagger definition is supplied 1`] = ` +exports[`rdme openapi:validate error handling should throw an error if an invalid Swagger definition is supplied 1`] = ` [SyntaxError: Swagger schema validation failed. ADDITIONAL PROPERTY must NOT have additional properties diff --git a/__tests__/cmds/validate.test.ts b/__tests__/cmds/openapi/validate.test.ts similarity index 86% rename from __tests__/cmds/validate.test.ts rename to __tests__/cmds/openapi/validate.test.ts index 605e5a29c..84fd17fa9 100644 --- a/__tests__/cmds/validate.test.ts +++ b/__tests__/cmds/openapi/validate.test.ts @@ -4,12 +4,14 @@ import fs from 'fs'; import chalk from 'chalk'; import prompts from 'prompts'; -import Command from '../../src/cmds/validate'; -import { after, before } from '../helpers/get-gha-setup'; +import OpenAPIValidateCommand from '../../../src/cmds/openapi/validate'; +import ValidateAliasCommand from '../../../src/cmds/validate'; +import { after, before } from '../../helpers/get-gha-setup'; const testWorkingDir = process.cwd(); -const validate = new Command(); +const validate = new OpenAPIValidateCommand(); +const validateAlias = new ValidateAliasCommand(); let consoleSpy; @@ -17,7 +19,7 @@ const getCommandOutput = () => { return [consoleSpy.mock.calls.join('\n\n')].filter(Boolean).join('\n\n'); }; -describe('rdme validate', () => { +describe('rdme openapi:validate', () => { beforeEach(() => { consoleSpy = jest.spyOn(console, 'info').mockImplementation(); }); @@ -208,3 +210,34 @@ describe('rdme validate', () => { }); }); }); + +describe('rdme validate', () => { + let consoleWarnSpy; + + const getWarningCommandOutput = () => { + return [consoleWarnSpy.mock.calls.join('\n\n')].filter(Boolean).join('\n\n'); + }; + + beforeEach(() => { + consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(); + }); + + afterEach(() => { + consoleWarnSpy.mockRestore(); + }); + + it('should should `rdme openapi:validate`', async () => { + await expect( + validateAlias.run({ + spec: require.resolve('@readme/oas-examples/3.0/json/petstore.json'), + }) + ).resolves.toContain(chalk.green('petstore.json is a valid OpenAPI API definition!')); + + expect(console.warn).toHaveBeenCalledTimes(1); + + const output = getWarningCommandOutput(); + expect(output).toBe( + chalk.yellow('⚠️ Warning! `rdme validate` has been deprecated. Please use `rdme openapi:validate` instead.') + ); + }); +}); diff --git a/__tests__/lib/__snapshots__/commands.test.ts.snap b/__tests__/lib/__snapshots__/commands.test.ts.snap index 4333fd384..3ceb6b338 100644 --- a/__tests__/lib/__snapshots__/commands.test.ts.snap +++ b/__tests__/lib/__snapshots__/commands.test.ts.snap @@ -37,6 +37,12 @@ Object { "description": "Reduce an OpenAPI definition into a smaller subset.", "hidden": false, "name": "openapi:reduce", + "position": 2, + }, + Object { + "description": "Validate your OpenAPI/Swagger definition.", + "hidden": false, + "name": "openapi:validate", "position": 3, }, Object { @@ -46,10 +52,10 @@ Object { "position": 4, }, Object { - "description": "Validate your OpenAPI/Swagger definition.", - "hidden": false, + "description": "Alias for \`rdme openapi:validate\` [deprecated].", + "hidden": true, "name": "validate", - "position": 2, + "position": 5, }, ], "description": "Upload OpenAPI/Swagger definitions", diff --git a/__tests__/lib/__snapshots__/createGHA.test.ts.snap b/__tests__/lib/__snapshots__/createGHA.test.ts.snap index 4593ef6eb..67f6ae514 100644 --- a/__tests__/lib/__snapshots__/createGHA.test.ts.snap +++ b/__tests__/lib/__snapshots__/createGHA.test.ts.snap @@ -574,17 +574,17 @@ jobs: " `; -exports[`#createGHA command inputs validate should run GHA creation workflow and generate valid workflow file 1`] = ` +exports[`#createGHA command inputs openapi:validate should run GHA creation workflow and generate valid workflow file 1`] = ` " Your GitHub Actions workflow file has been created! ✨ -Almost done! Push your newly created file (.github/workflows/rdme-validate.yml) to GitHub and you're all set 🚀 +Almost done! Push your newly created file (.github/workflows/rdme-openapi-validate.yml) to GitHub and you're all set 🚀 🦉 If you have any more questions, feel free to drop us a line! support@readme.io " `; -exports[`#createGHA command inputs validate should run GHA creation workflow and generate valid workflow file 2`] = ` +exports[`#createGHA command inputs openapi:validate should run GHA creation workflow and generate valid workflow file 2`] = ` "# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z # You can view our full documentation here: https://docs.readme.com/docs/rdme name: ReadMe GitHub Action 🦉 @@ -598,30 +598,30 @@ on: - some-branch jobs: - rdme-validate: + rdme-openapi-validate: runs-on: ubuntu-latest steps: - name: Check out repo 📚 uses: actions/checkout@v3 - - name: Run \`validate\` command 🚀 + - name: Run \`openapi:validate\` command 🚀 uses: readmeio/rdme@7.8.9 with: - rdme: validate petstore.json + rdme: openapi:validate petstore.json " `; -exports[`#createGHA command inputs validate should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 1`] = ` +exports[`#createGHA command inputs openapi:validate should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 1`] = ` " Your GitHub Actions workflow file has been created! ✨ -Almost done! Push your newly created file (.github/workflows/rdme-validate-with-github-flag.yml) to GitHub and you're all set 🚀 +Almost done! Push your newly created file (.github/workflows/rdme-openapi-validate-with-github-flag.yml) to GitHub and you're all set 🚀 🦉 If you have any more questions, feel free to drop us a line! support@readme.io " `; -exports[`#createGHA command inputs validate should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 2`] = ` +exports[`#createGHA command inputs openapi:validate should run GHA creation workflow with \`--github\` flag and messy file name and generate valid workflow file 2`] = ` "# This GitHub Actions workflow was auto-generated by the \`rdme\` cli on 2022-01-01T00:00:00.000Z # You can view our full documentation here: https://docs.readme.com/docs/rdme name: ReadMe GitHub Action 🦉 @@ -635,15 +635,15 @@ on: - another-branch jobs: - rdme-validate: + rdme-openapi-validate: runs-on: ubuntu-latest steps: - name: Check out repo 📚 uses: actions/checkout@v3 - - name: Run \`validate\` command 🚀 + - name: Run \`openapi:validate\` command 🚀 uses: readmeio/rdme@7.8.9 with: - rdme: validate petstore.json + rdme: openapi:validate petstore.json " `; diff --git a/__tests__/lib/createGHA.test.ts b/__tests__/lib/createGHA.test.ts index a2abc5bff..1b987874e 100644 --- a/__tests__/lib/createGHA.test.ts +++ b/__tests__/lib/createGHA.test.ts @@ -15,7 +15,7 @@ import SingleCustomPageCommand from '../../src/cmds/custompages/single'; import DocsCommand from '../../src/cmds/docs'; import SingleDocCommand from '../../src/cmds/docs/single'; import OpenAPICommand from '../../src/cmds/openapi'; -import ValidateCommand from '../../src/cmds/validate'; +import OpenAPIValidateCommand from '../../src/cmds/openapi/validate'; import configstore from '../../src/lib/configstore'; import createGHA, { getConfigStoreKey, @@ -60,7 +60,7 @@ describe('#createGHA', () => { CmdClass: typeof Command; opts: CommandOptions>; }>([ - { cmd: 'validate', CmdClass: ValidateCommand, opts: { spec: 'petstore.json' } }, + { cmd: 'openapi:validate', CmdClass: OpenAPIValidateCommand, opts: { spec: 'petstore.json' } }, { cmd: 'openapi', CmdClass: OpenAPICommand, opts: { key, spec: 'petstore.json', id: 'spec_id' } }, { cmd: 'docs', CmdClass: DocsCommand, opts: { key, folder: './docs', version: '1.0.0' } }, { cmd: 'docs:single', CmdClass: SingleDocCommand, opts: { key, filePath: './docs/rdme.md', version: '1.0.0' } }, diff --git a/src/cmds/index.ts b/src/cmds/index.ts index cca7d09b6..3a1e61554 100644 --- a/src/cmds/index.ts +++ b/src/cmds/index.ts @@ -13,8 +13,9 @@ import OASCommand from './oas'; import OpenCommand from './open'; import OpenAPICommand from './openapi'; import OpenAPIReduceCommand from './openapi/reduce'; +import OpenAPIValidateCommand from './openapi/validate'; import SwaggerCommand from './swagger'; -import ValidateCommand from './validate'; +import ValidateAliasCommand from './validate'; import VersionsCommand from './versions'; import CreateVersionCommand from './versions/create'; import DeleteVersionCommand from './versions/delete'; @@ -46,8 +47,9 @@ const commands = { open: OpenCommand, openapi: OpenAPICommand, 'openapi:reduce': OpenAPIReduceCommand, + 'openapi:validate': OpenAPIValidateCommand, swagger: SwaggerCommand, - validate: ValidateCommand, + validate: ValidateAliasCommand, whoami: WhoAmICommand, }; diff --git a/src/cmds/openapi/reduce.ts b/src/cmds/openapi/reduce.ts index f4e8c4e5f..682e06f0d 100644 --- a/src/cmds/openapi/reduce.ts +++ b/src/cmds/openapi/reduce.ts @@ -26,7 +26,7 @@ export default class OpenAPIReduceCommand extends Command { this.usage = 'openapi:reduce [file] [options]'; this.description = 'Reduce an OpenAPI definition into a smaller subset.'; this.cmdCategory = CommandCategories.APIS; - this.position = 3; + this.position = 2; this.hiddenArgs = ['spec']; this.args = [ diff --git a/src/cmds/openapi/validate.ts b/src/cmds/openapi/validate.ts new file mode 100644 index 000000000..6cc8ad90c --- /dev/null +++ b/src/cmds/openapi/validate.ts @@ -0,0 +1,54 @@ +import type { CommandOptions } from '../../lib/baseCommand'; + +import chalk from 'chalk'; + +import Command, { CommandCategories } from '../../lib/baseCommand'; +import createGHA from '../../lib/createGHA'; +import prepareOas from '../../lib/prepareOas'; + +export type Options = { + spec?: string; + workingDirectory?: string; +}; + +export default class OpenAPIValidateCommand extends Command { + constructor() { + super(); + + this.command = 'openapi:validate'; + this.usage = 'openapi:validate [file] [options]'; + this.description = 'Validate your OpenAPI/Swagger definition.'; + this.cmdCategory = CommandCategories.APIS; + this.position = 3; + + this.hiddenArgs = ['spec']; + this.args = [ + { + name: 'spec', + type: String, + defaultOption: true, + }, + { + name: 'workingDirectory', + type: String, + description: 'Working directory (for usage with relative external references)', + }, + this.getGitHubArg(), + ]; + } + + async run(opts: CommandOptions) { + super.run(opts); + + const { spec, workingDirectory } = opts; + + if (workingDirectory) { + process.chdir(workingDirectory); + } + + const { specPath, specType } = await prepareOas(spec, 'openapi:validate'); + return Promise.resolve(chalk.green(`${specPath} is a valid ${specType} API definition!`)).then(msg => + createGHA(msg, this.command, this.args, { ...opts, spec: specPath } as CommandOptions) + ); + } +} diff --git a/src/cmds/validate.ts b/src/cmds/validate.ts index 3d034df00..c68a72987 100644 --- a/src/cmds/validate.ts +++ b/src/cmds/validate.ts @@ -1,54 +1,24 @@ import type { CommandOptions } from '../lib/baseCommand'; +import type { Options } from './openapi/validate'; -import chalk from 'chalk'; +import Command from '../lib/baseCommand'; +import isHidden from '../lib/decorators/isHidden'; -import Command, { CommandCategories } from '../lib/baseCommand'; -import createGHA from '../lib/createGHA'; -import prepareOas from '../lib/prepareOas'; +import OpenAPIValidateCommand from './openapi/validate'; -export type Options = { - spec?: string; - workingDirectory?: string; -}; - -export default class ValidateCommand extends Command { +@isHidden +export default class ValidateAliasCommand extends OpenAPIValidateCommand { constructor() { super(); this.command = 'validate'; this.usage = 'validate [file] [options]'; - this.description = 'Validate your OpenAPI/Swagger definition.'; - this.cmdCategory = CommandCategories.APIS; - this.position = 2; - - this.hiddenArgs = ['spec']; - this.args = [ - { - name: 'spec', - type: String, - defaultOption: true, - }, - { - name: 'workingDirectory', - type: String, - description: 'Working directory (for usage with relative external references)', - }, - this.getGitHubArg(), - ]; + this.description = 'Alias for `rdme openapi:validate` [deprecated].'; + this.position = 5; } async run(opts: CommandOptions) { - super.run(opts); - - const { spec, workingDirectory } = opts; - - if (workingDirectory) { - process.chdir(workingDirectory); - } - - const { specPath, specType } = await prepareOas(spec, 'validate'); - return Promise.resolve(chalk.green(`${specPath} is a valid ${specType} API definition!`)).then(msg => - createGHA(msg, this.command, this.args, { ...opts, spec: specPath } as CommandOptions) - ); + Command.warn('`rdme validate` has been deprecated. Please use `rdme openapi:validate` instead.'); + return super.run(opts); } } diff --git a/src/lib/prepareOas.ts b/src/lib/prepareOas.ts index 0eea36d40..cdcf0d76d 100644 --- a/src/lib/prepareOas.ts +++ b/src/lib/prepareOas.ts @@ -19,7 +19,7 @@ type FileSelection = { * @param command The command context in which this is being run within (uploading a spec, * validation, or reducing one). */ -export default async function prepareOas(path: string, command: 'openapi' | 'openapi:reduce' | 'validate') { +export default async function prepareOas(path: string, command: 'openapi' | 'openapi:reduce' | 'openapi:validate') { let specPath = path; if (!specPath) { @@ -45,11 +45,8 @@ export default async function prepareOas(path: string, command: 'openapi' | 'ope case 'openapi': action = 'upload'; break; - case 'openapi:reduce': - action = 'reduce'; - break; default: - action = command; + action = command.split(':')[1] as 'reduce' | 'validate'; } const jsonAndYamlFiles = readdirRecursive('.', true).filter(