Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(openapi): add postman warning #851

Draft
wants to merge 15 commits into
base: next
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cmds/openapi/validate.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mind reverting this change?

Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export default class OpenAPIValidateCommand extends Command {
}

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 ZeroAuthCommandOptions<Options>),
);
Expand Down
30 changes: 29 additions & 1 deletion src/lib/prepareOas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import OASNormalize, { getAPIDefinitionType } from 'oas-normalize';
import ora from 'ora';

import isCI from './isCI.js';
import { debug, info, oraOptions } from './logger.js';
import { debug, info, warn, oraOptions } from './logger.js';
import promptTerminal from './promptWrapper.js';
import readdirRecursive from './readdirRecursive.js';

Expand Down Expand Up @@ -211,6 +211,34 @@ export default async function prepareOas(
debug('spec bundled');
}

// Checks to see if the selected file is a postman collection and throws a warning in the console depending on the command.
if (definitionVersion.specification === 'postman') {
switch (command) {
case 'openapi':
Comment on lines +215 to +217
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great job here with this if/switch logic — super readable and it's in the perfect spot 👏🏽

warn(
'You are attempting to upload a Postman collection. This feature is currently experimental. For more information, visit our docs here: https://docs.readme.com/main/docs/openapi#the-api-reference',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small refactoring suggestion: mind creating a separate variable above (called postmanWarning or something like that) and re-using that in all of these warn statements?

);
break;
case 'openapi:validate':
warn(
'You are attempting to validate a Postman collection. This feature is currently experimental. For more information, visit our docs here: https://docs.readme.com/main/docs/openapi#the-api-reference',
);
break;
case 'openapi:inspect':
warn(
'You are inspecting a Postman collection. This feature is currently experimental. For more information, visit our docs here: https://docs.readme.com/main/docs/openapi#the-api-reference',
);
break;
case 'openapi:convert':
warn(
'You are attempting to convert a Postman collection to an OpenAPI file. This feature is currently experimental. For more information, visit our docs here: https://docs.readme.com/main/docs/openapi#the-api-reference',
);
break;
default:
debug(`Type ${chalk.yellow('rdme help')} to see all commands`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't think you need this debug statement, mind removing it?

}
}

return {
preparedSpec: JSON.stringify(api),
/** A string indicating whether the spec file is a local path, a URL, etc. */
Expand Down