Skip to content

CLI Reference

The Massimo CLI (massimo-cli) creates Fastify plugins that expose clients for remote OpenAPI or GraphQL APIs.

Terminal window
npx massimo-cli [url|file] [options]
# or if installed globally:
massimo [url|file] [options]

Generate a client plugin from an OpenAPI or GraphQL schema.

  • url|file - URL to the API schema or path to a local schema file
OptionAliasDescriptionDefault
--name <name>-nName of the clientRequired
--folder <name>-fName of the plugin folderSame as --name
--config <path>-cPath to the configuration file-
--module <esm|cjs>Module format (ESM or CommonJS)Auto-detect
--typescript-tGenerate the client plugin in TypeScriptfalse
--frontendGenerate browser-compatible client using fetchfalse
--language <js|ts>Language for frontend clientjs
--full-responseReturn full response object instead of just bodyfalse
--full-requestWrap parameters in body, headers, queryfalse
--fullEnable both --full-request and --full-responsefalse
--optional-headers <headers>Comma-separated headers marked as optional-
--validate-responseValidate response body against schemafalse
--url-auth-headers <headers>Auth headers for schema URL (JSON string)-
--types-onlyGenerate only TypeScript typesfalse
--types-commentAdd comment to generated .d.ts filefalse
--type-extensionForce TypeScript declaration file extensionsfalse
--with-credentialsAdd credentials: 'include' to fetch requestsfalse
--props-optionalDefine properties as optional unless requiredtrue
--skip-config-updateSkip updating Platformatic/Watt configtrue
--retry-timeout-ms <ms>Retry timeout for HTTP requests-

Generate OpenAPI client:

Terminal window
massimo http://example.com/openapi.json -n myclient

Generate GraphQL client:

Terminal window
massimo http://example.com/graphql -n myclient

Use local schema file:

Terminal window
massimo path/to/schema.json -n myclient

Generate ESM client:

Terminal window
massimo https://api.example.com/openapi.json --name my-api --module esm

Generate CommonJS client:

Terminal window
massimo https://api.example.com/openapi.json --name my-api --module cjs

Auto-detect module format from package.json:

Terminal window
# Detects from "type": "module" in package.json
massimo https://api.example.com/openapi.json --name my-api

TypeScript plugin:

Terminal window
massimo https://api.example.com/openapi.json --name my-api --typescript

Frontend client with TypeScript:

Terminal window
massimo https://api.example.com/openapi.json --frontend --language ts --name my-api

Types only:

Terminal window
massimo https://api.example.com/openapi.json --types-only --name my-api

Force TypeScript declaration file extensions:

Terminal window
# Generate .d.mts for ESM or .d.cts for CommonJS based on module format
massimo https://api.example.com/openapi.json --types-only --type-extension --name my-api

Full response/request objects:

Terminal window
massimo https://api.example.com/openapi.json --full --name my-api

With authentication headers:

Terminal window
massimo https://private-api.com/openapi.json \
--url-auth-headers '{"Authorization":"Bearer TOKEN"}' \
--name private-api

Browser client with credentials:

Terminal window
massimo https://api.example.com/openapi.json \
--frontend \
--with-credentials \
--name my-api

Massimo automatically detects your project’s module format:

  1. ESM (ECMAScript Modules): Generated when your package.json contains "type": "module"

    • Output files use .mjs extension
    • Uses import/export syntax
  2. CommonJS: Generated when package.json doesn’t have "type": "module" or has "type": "commonjs"

    • Output files use .cjs extension
    • Uses require/module.exports syntax
  3. Override: Use --module esm or --module cjs to force a specific format

When generating TypeScript declaration files, Massimo can intelligently determine the appropriate file extension:

  • TypeScript declaration files are generated with the .d.ts extension by default

When you use the --type-extension flag, Massimo generates module-specific TypeScript declaration files:

  1. ESM Projects: Generates .d.mts files (TypeScript declaration for ESM modules)
  2. CommonJS Projects: Generates .d.cts files (TypeScript declaration for CommonJS modules)

The TypeScript declaration file extension is determined by the following precedence:

  1. Explicit --type-extension flag: Forces generation of module-specific extensions
  2. Module format: Based on --module flag or detected module type from package.json
  3. Parent package.json: Falls back to the "type" field in the parent package.json
Terminal window
# Generate .d.mts for ESM project
massimo https://api.example.com/openapi.json --types-only --type-extension --module esm --name my-api
# Generate .d.cts for CommonJS project
massimo https://api.example.com/openapi.json --types-only --type-extension --module cjs --name my-api
# Auto-detect and generate appropriate extension
massimo https://api.example.com/openapi.json --types-only --type-extension --name my-api