A dynamic mock server that provides OpenAPI spec-compliant endpoints for the Optum Perks Online Care API. Built with Mockoon and designed for both development and testing environments.
# Install dependencies
npm install
# Generate mock data
npm run pipeline
# Start server
npx mockoon-cli start -d ./src/mockoon_env.final.json
# Build and start
docker compose up --build
# Access the server
curl http://localhost:3005/api/v1
The mock server will be available at http://localhost:3005/api/v1
The mock server automatically transforms an OpenAPI specification into a functioning mock server through a series of steps:
graph TD
A[OpenAPI Spec YAML] --> B[Create Mockoon Env]
B --> C[Generate Types]
C --> D[Write Mock Data]
D --> E[Add Dynamic Rules]
E --> F[Update Environment]
F --> G[Final Mock Server]
-
Create Mockoon Environment (
npm run create-mockoon
)- Converts OpenAPI spec to Mockoon config
- Sets up base routes and responses
-
Generate API Types (
npm run api-types
)- Creates TypeScript definitions
- Ensures type safety
-
Write Mock Data (
npm run write-data
)- Generates spec-compliant dynamic response chains
- Populates data templates
-
Add Dynamic Rules (
npm run add-rules
)- Configures path parameters
- Sets up response rules
-
Update Environment (
npm run update-env
)- Configures server settings
- Sets final environment
# Run entire pipeline
npm run pipeline
# Or run steps individually
npm run create-mockoon
npm run api-types
npm run write-data
npm run add-rules
npm run update-env
├── config/ # API specification
│ └── openapi.yml # OpenAPI spec file
├── scripts/ # Build and generation scripts
│ ├── pipeline.js # Main pipeline script
│ ├── apiTypes.js # Type generation
│ └── ... # Other utilities
├── src/
│ ├── responses/ # Response templates
│ ├── mock-data/ # Mock data sources
│ └── mockoonFile.json # Mockoon configuration
└── docker-compose.yml # Docker configuration
- by default, moockon will use faker.js to generate mock responses
- unless there are explicit examples given in the spec yaml. if those exist, they will be served
- If more than one example exists (i.e. for non-2XX level responses) you can pick the example you want by using the example name as the path variable
- Scripts to build explicit mock structures for domains like conditions ,guestVisits etc are run, and those results are also served.
The mock server configuration should never be edited manually. To update:
-
Update API Specification
# 1. Replace OpenAPI spec cp new-spec.yml ./config/openapi.yml # 2. Run pipeline npm run pipeline
-
Add New Mock Data
- Add templates to
src/responses/
- Add data sources to
src/mock-data/
- Run
npm run write-data
- Add templates to
-
Modify Response Rules
- Update rules in response templates
- Run
npm run add-rules
Base URL: http://localhost:3005/api/v1
Example endpoints:
- GET
/conditions
- GET
/conditions/:id
- [Add other key endpoints here]
# Build production image
docker build -t your-registry/mockoon-server:version .
# Push to registry
docker push your-registry/mockoon-server:version
# Deploy
docker compose -f docker-compose.prod.yml up -d
# .env file
PORT=3005
NODE_ENV=production
- Pipeline behavior can be modified in
scripts/pipeline.js
- Custom steps can be added through
package.json
scripts - Error handling can be adjusted in pipeline scripts
- Port settings in
src/mockoon_env.final.json
- Response delays and codes in response templates
- Dynamic rules in route configurations
-
Pipeline Failures
# Check pipeline logs npm run pipeline -- --verbose
-
Missing Mock Data
# Regenerate mock data npm run write-data
-
Server Won't Start
- Check port availability
- Verify JSON configuration
- Ensure all dependencies are installed
-
Failed: Create Mockoon JSON env
- Verify OpenAPI spec format
- Check file permissions
-
Error: Port already in use
- Change port in environment variables
- Kill existing server process
- Check Mockoon documentation
- Review pipeline logs
- Verify OpenAPI spec compatibility
- Never edit
mockoon_env.final.json
manually - Run full pipeline after changes
- Test all endpoints before deployment
- Maintain type safety with generated types
For more information about Mockoon, visit mockoon.com