Monorepo Support
Auto-detect sub-packages in a Monorepo and generate API code
If your project is a Monorepo, worma automatically reads the workspaces field in the root package.json or pnpm-workspace.yaml, detects sub-packages, and runs the generation command in each sub-package that contains a worma.config.[j|ts].
How it works
Example project structure
Usage
Run in the Monorepo root:
worma genworma automatically:
- Reads
package.json'sworkspacesorpnpm-workspace.yaml - Traverses all sub-package directories
- Runs generation in each sub-package that contains a
worma.config.[j|ts]or.wormarc - Aggregates and shows the generation status of all sub-packages
Generate a single sub-package
If you only need one sub-package's API code, use --project to point at it:
worma gen --project ./packages/user-serviceThis skips the Monorepo scan and generates only in the specified sub-package.
Sub-package config example
Each sub-package can configure its own OpenAPI URL, template, and plugins independently:
// packages/user-service/worma.config.js
import { defineConfig } from 'wormajs';
import { axios } from 'wormajs/plugin';
import { aiDoc } from 'wormajs/plugin';
export default defineConfig({
generator: [
{
input: 'https://user-service.example.com/openapi.json',
output: 'src/api',
serverName: 'User Service',
plugins: [axios(), aiDoc()],
},
],
});Manage centrally from the root
You can also configure all sub-services centrally in the root worma.config:
import { defineConfig } from 'wormajs';
import { axios } from 'wormajs/plugin';
export default defineConfig({
generator: [
{
input: 'https://user-service.example.com/openapi.json',
output: 'packages/user-service/src/api',
serverName: 'User Service',
plugins: [axios()],
},
{
input: 'https://order-service.example.com/openapi.json',
output: 'packages/order-service/src/api',
serverName: 'Order Service',
plugins: [axios()],
},
],
});When managing centrally from the root, each generator's
outputshould point to the corresponding sub-package directory, and it is recommended to setserverNamefor each.