ReadMe CLI
rdme is the official command-line interface (CLI) and GitHub Action for ReadMe, designed to streamline API documentation workflows. It enables users to manage and synchronize API definitions (supporting OpenAPI, Swagger, and Postman specifications) with their API reference documentation hosted on ReadMe.com. Beyond ReadMe-specific integrations, it provides robust API definition validation tools that can be used independently, without requiring a ReadMe account. The current stable version is v10.6.2, with active development indicated by frequent patch and minor releases, often with pre-release (`-next`) versions for upcoming features. A key differentiator is its dual functionality as both a local development tool and an automation agent for CI/CD environments, specifically via GitHub Actions. It has a notable distinction between v9 and v10 regarding compatibility with 'ReadMe Refactored' documentation experiences.
Common errors
-
command not found: rdme
cause The `rdme` package is not installed globally or is not in your system's PATH.fixInstall `rdme` globally using `npm install -g rdme`. If already installed, ensure your npm global bin directory is included in your system's PATH environment variable. -
Error: Node.js vX.Y.Z is not supported. Please upgrade to Node.js v20.10.0 or higher.
cause Your current Node.js version does not meet the minimum requirement for `rdme`.fixUpgrade Node.js to version 20.10.0 or newer. Use `nvm install 20 && nvm use 20` or download the latest LTS version from nodejs.org. -
Error: You are not authenticated with ReadMe. Please provide a ReadMe API key.
cause Commands requiring interaction with ReadMe.com (e.g., `openapi upload`, `docs create`) need authentication.fixLog in using `rdme login` or provide your API key via the `--key` flag or `RDME_API_KEY` environment variable. Your API key can be found in your ReadMe dashboard. -
Error: 'openapi.yaml' is not a valid OpenAPI/Swagger definition.
cause The specified file has syntactical or structural errors according to the OpenAPI/Swagger specification.fixUse `rdme openapi validate <filename>` to get detailed error messages and fix the issues in your OpenAPI definition. Tools like VS Code with OpenAPI extensions can also help.
Warnings
- breaking Major architectural changes in `rdme@10` make it incompatible with older ReadMe documentation platforms. If you are not using 'ReadMe Refactored', you must stick to `rdme@9` or earlier to avoid issues.
- breaking The `rdme` CLI now requires Node.js version 20.10.0 or higher. Older Node.js versions will prevent the CLI from running.
- gotcha As of v10.6.0, JavaScript execution in frontmatter has been disabled for security reasons. Relying on this feature in your ReadMe content will result in unexpected behavior or errors.
- gotcha The `--working-directory` flag for OpenAPI uploads was temporarily broken or missing in some v10.5.x releases and was restored in v10.5.3.
Install
-
npm install rdme -
yarn add rdme -
pnpm add rdme
Imports
- run
import { run } from 'rdme' - upload
import { upload } from 'rdme' - validate
import { validate } from 'rdme'
Quickstart
import { validate, run } from 'rdme';
async function quickstart() {
console.log('--- Validating an OpenAPI specification programmatically ---');
try {
// Assuming 'openapi.yaml' exists in the current directory
await validate(['openapi.yaml']);
console.log('OpenAPI specification is valid!');
} catch (error) {
console.error('Validation failed:', error.message);
// For a real application, you might exit with an error code here.
}
console.log('\n--- Running a CLI command programmatically ---');
try {
// Simulate `rdme openapi validate openapi.yaml`
// Note: 'run' may suppress console output for success by default,
// or throw on error. Error handling is crucial.
console.log('Attempting to run `rdme openapi validate` via `run()`...');
await run(['openapi', 'validate', 'openapi.yaml']);
console.log('CLI command executed successfully via `run()`.');
} catch (error) {
console.error('CLI command failed:', error.message);
}
console.log('\n--- Typical CLI usage via npm ---');
console.log('To install globally: npm install -g rdme');
console.log('Then, validate: rdme openapi validate openapi.yaml');
}
// Create a dummy openapi.yaml for demonstration purposes
import * as fs from 'node:fs';
if (!fs.existsSync('openapi.yaml')) {
fs.writeFileSync('openapi.yaml', `
openapi: 3.0.0
info:
title: My API
version: 1.0.0
paths:
/items:
get:
summary: Retrieve items
responses:
'200':
description: A list of items
`)
}
quickstart();