@mhmdalimansour/mock-mock
v1.1.1
Published
Production-grade CLI tool to generate mock servers from Confluence API documentation
Readme
MockMock
MockMock is a TypeScript CLI that turns Confluence API documentation into a running mock API server.
It fetches a Confluence page or local HTML export, parses endpoint definitions into a normalized schema, and starts an Express server that returns generated yet stateful mock responses. It is useful when frontend or integration work needs a realistic API before the real backend is ready.
What This Project Does
- Reads API definitions from Confluence pages or exported HTML files
- Extracts endpoints from both table-based ERD pages and code blocks
- Starts an Express server with dynamically registered routes
- Generates realistic response data with
@faker-js/faker - Keeps data in memory so
GET,POST,PUT,PATCH, andDELETEbehave like a lightweight API - Optionally proxies unmatched requests to a fallback server
- Lets you simulate latency with startup flags, runtime endpoints, or stdin commands
How It Works
MockMock has four main steps:
- The CLI in
src/cli.tsreads command-line options and environment variables. - The fetcher in
src/fetcher/confluence.tsloads HTML from:- a
file://path - a public Confluence page
- an authenticated Atlassian Confluence page via REST API
- a
- The parser in
src/parser/erd-parser.tsconverts the HTML into aMockSchema. - The server in
src/server/mock-server.tsregisters routes and serves responses backed by the in-memoryDataStore.
Runtime Behavior
GETlist endpoints return a generated collection if the response template contains an array.GETitem endpoints return one stored record when a matching item exists.POSTcreates a new in-memory record.PUTandPATCHupdate an existing record by id.DELETEremoves an existing record and returns204.- If no stored collection exists for an endpoint, MockMock falls back to generating data from the response template on demand.
Architecture
mock-mock/
├── src/
│ ├── cli.ts
│ ├── fetcher/
│ │ └── confluence.ts
│ ├── parser/
│ │ ├── erd-parser.ts
│ │ └── schema-types.ts
│ └── server/
│ ├── data-generator.ts
│ ├── data-store.ts
│ └── mock-server.ts
├── example-confluence.html
├── package.json
└── tsconfig.jsonCore Modules
src/cli.ts: entrypoint, option parsing, orchestrationsrc/fetcher/confluence.ts: Confluence and local-file fetchingsrc/parser/erd-parser.ts: HTML parsing and endpoint extractionsrc/parser/schema-types.ts: shared contract between parser and serversrc/server/data-generator.ts: fake response generationsrc/server/data-store.ts: in-memory collections and CRUD-like behaviorsrc/server/mock-server.ts: Express app, route registration, fallback proxy, health/config endpoints
Installation
Install From npm
npm install -g @mhmdalimansour/mock-mockThis installs the package published on npm as @mhmdalimansour/mock-mock and exposes the CLI command mock-mock.
Local Development
npm installBuild the CLI
npm run buildGlobal Usage
After installing globally, the CLI command is:
mock-mock --url <confluence-url>Quick Start
1. Run Against the Example HTML
npm run dev -- --url file://C:/absolute/path/to/example-confluence.html --port 4000On macOS or Linux:
npm run dev -- --url file:///absolute/path/to/example-confluence.html --port 40002. Run Against a Confluence Page
npm run dev -- --url https://your-domain.atlassian.net/wiki/spaces/SPACE/pages/123456/Page+Title --port 40003. Test the Server
curl http://localhost:4000/health
curl http://localhost:4000/api/users
curl -X POST http://localhost:4000/api/users -H "Content-Type: application/json" -d "{\"name\":\"John\"}"CLI Usage
Development Mode
npm run dev -- --url <url>Run the Built CLI
npm start -- --url <url>CLI Options
| Option | Description | Default |
| --- | --- | --- |
| -u, --url <url> | Confluence page URL or file:// HTML path | required |
| -p, --port <port> | Port for the mock server | 4000 |
| -f, --fallback <url> | Base URL used for truncated-response hydration during parsing and as a proxy target for unmatched runtime requests | none |
| --delay <ms> | Response delay in milliseconds | 0 |
| -e, --email <email> | Confluence email, overrides env var | none |
| -t, --token <token> | Confluence API token, overrides env var | none |
| -d, --debug | Save fetched HTML to debug.html and print parsed schema | false |
Example Commands
npm run dev -- --url file:///tmp/exported-page.html --port 4000
npm run dev -- --url https://your-domain.atlassian.net/wiki/spaces/SPACE/pages/123456/Page+Title --delay 500
npm run dev -- --url https://your-domain.atlassian.net/wiki/spaces/SPACE/pages/123456/Page+Title --fallback https://api.dev.example.comAuthentication
Private Confluence pages usually require credentials.
Create a .env file or export the following variables:
[email protected]
CONFLUENCE_API_TOKEN=your-api-tokenYou can also pass them directly:
npm run dev -- --url <url> --email [email protected] --token your-api-tokenFetching Rules
file://...reads a local HTML file- Atlassian Cloud URLs with credentials use the Confluence REST API
- Other URLs are fetched as raw HTML
- If Confluence returns a login page instead of the document, MockMock exits with an authentication error
For more setup details, see AUTH_SETUP.md.
Supported Input Formats
MockMock currently supports two Confluence patterns:
- table-based endpoint documentation
- code blocks containing endpoint definitions
Code Block Format
POST /api/categories
Request:
{
"name": "string"
}
Response:
{
"id": 1,
"name": "string"
}
Status: 201Supported Methods
- Table-based parsing supports
GET,POST,PUT,PATCH, andDELETE. - Plain code-block parsing currently recognizes
GET,POST,PUT,PATCH, andDELETE. - The server runtime supports
PATCHonce an endpoint is present in the parsed schema.
Notes About Response Templates
- Response objects are used as templates for fake data generation.
- Response arrays are expanded into collections with about 15 to 30 records.
- Wrapped collections such as
{ "errors": false, "data": [...] }are preserved. - If a table-based
Response Structurecontains....., MockMock treats it as a truncated example, fetches the live payload from--fallbackfor safe read-only endpoints, then adds any documented fields that are missing from that payload. - Path parameters in documentation can use
{id}and are converted to Express-style params internally. - Plain code-block parsing is best with object-shaped JSON responses; table-based ERD pages are more flexible.
Server Endpoints
In addition to parsed API routes, MockMock exposes a few built-in endpoints:
| Endpoint | Method | Purpose |
| --- | --- | --- |
| /health | GET | Shows registered endpoints and current configuration |
| /_config/delay | GET | Returns current response delay |
| /_config/delay | PUT | Updates response delay at runtime |
You can also change delay from stdin while the server is running:
delay 500
delayDeveloper Guide
Scripts
npm install
npm run build
npm run dev -- --url file://C:/absolute/path/to/example-confluence.html
npm start -- --url file://C:/absolute/path/to/example-confluence.htmlTech Stack
- TypeScript
- Commander
- Axios
- Cheerio
- Express
- Faker
Development Flow
- Update fetching logic in
src/fetcher/if the Confluence source format changes. - Update parsing logic in
src/parser/when new ERD/table/code patterns need to be supported. - Keep
MockEndpointandMockSchemainsrc/parser/schema-types.tsas the contract between layers. - Update server behavior in
src/server/when changing how routes, state, or fake responses work. - Run
npm run buildto verify TypeScript compilation.
Important Design Choices
- The parser and server communicate through a simple schema contract.
- The server is stateful only in memory; restarting the process resets all data.
- Fake data generation is template-driven, so response structure depends on the documentation input.
- Collections are derived from
GETendpoints that expose arrays in the response template.
Project Structure for Contributors
example-confluence.html: local test fixtureREADME.md: main project documentationAUTH_SETUP.md: authentication helpQUICKSTART.md: short setup walkthroughCONTRIBUTING.md: contributor notes
Troubleshooting
No endpoints found
- Check that the Confluence page contains supported tables or code blocks.
- Use
--debugto savedebug.htmland inspect the fetched HTML.
Authentication failed
- Verify
CONFLUENCE_EMAILandCONFLUENCE_API_TOKEN. - Confirm the page is accessible to that account.
- For Atlassian Cloud, make sure the URL contains a valid
/pages/<id>/segment.
Unexpected response shape
- Check the response JSON in Confluence.
- Make sure wrapped arrays or nested objects are valid JSON.
- For truncated
.....examples, provide--fallbackso MockMock can hydrate the missing structure from the live API. - Parse-time fallback hydration is limited to read-only endpoints such as
GET; non-GETendpoints keep the documented fields only. - Remember that fake data is inferred from field names and primitive types.
Changes disappear after restart
This is expected. Data is stored only in memory.
Example Output
MockMock CLI
Fetching Confluence page: https://confluence.example.com/pages/123456
Page fetched successfully
Parsing API endpoints...
Found 3 endpoint(s)
Registering endpoints:
GET /api/users
POST /api/users
DELETE /api/users/:id
Mock server started successfully
Base URL: http://localhost:4000
Health check: http://localhost:4000/healthLicense
MIT
