4f021012f6f991646faa4edae099ab6e2c80428c
MockAPI
OpenAPI Mock Server Generator - Generate functional mock APIs from OpenAPI 3.x specifications.
Features
- OpenAPI 3.x Support: Parse and validate OpenAPI specifications
- Mock Server Generation: Generate working mock servers using connexion
- Random Data Generation: Create realistic test data from JSON schemas using Faker
- Configurable Response Delays: Simulate network latency with fixed or random delays
- Error Simulation: Simulate HTTP error responses for testing
- Request Validation: Validate incoming requests against OpenAPI spec
- Hot-Reload: Auto-restart server on spec file changes
- YAML Configuration: Configure mock behavior via
mockapi.yaml
Installation
pip install -e .
Or install from source:
git clone https://7000pct.gitea.bloupla.net/7000pctAUTO/mockapi.git
cd mockapi
pip install -e ".[dev]"
Quick Start
# Validate an OpenAPI spec
mockapi validate examples/petstore.yaml
# Start a mock server
mockapi start examples/petstore.yaml
# Generate a summary
mockapi generate examples/petstore.yaml
CLI Commands
validate
Validate an OpenAPI specification file:
mockapi validate spec.yaml
start
Start a mock server from an OpenAPI spec:
mockapi start spec.yaml --port 8080 --host 0.0.0.0
Options:
--port, -p: Port number (default: 8080)--host, -h: Host to bind to (default: 0.0.0.0)--delay, -d: Fixed response delay in milliseconds--random-delay: Use random delays instead of fixed--config, -c: Path to mockapi.yaml configuration--watch, -w: Enable hot-reload on spec changes--verbose, -v: Enable verbose output
generate
Generate a summary from an OpenAPI spec:
mockapi generate spec.yaml
show-config
Show current configuration:
mockapi show-config
Configuration
Create a mockapi.yaml file to configure mock behavior:
port: 8080
host: 0.0.0.0
delay: 100
random_delay: false
seed: 42
validate_requests: true
error_probability: 0.0
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
| port | int | 8080 | Server port |
| host | string | 0.0.0.0 | Server host |
| delay | int | 0 | Fixed delay in ms |
| random_delay | bool | false | Use random delays |
| seed | int | 42 | Random seed |
| validate_requests | bool | true | Validate requests |
| error_probability | float | 0.0 | Error probability |
Environment Variables
MOCKAPI_PORT: Override default portMOCKAPI_HOST: Override default hostMOCKAPI_SEED: Override random seed
Hot Reload
Enable automatic server restart when the spec file changes:
mockapi start spec.yaml --watch
Request Validation
By default, incoming requests are validated against the OpenAPI spec. Disable with:
validate_requests: false
Error Simulation
Use the x-mock-config extension in your OpenAPI spec:
paths:
/users:
get:
x-mock-config:
errorProbability: 0.1
errorCode: 500
errorMessage: "Service unavailable"
Development
# Install development dependencies
pip install -e ".[dev]"
# Run tests
pytest tests/ -v
# Run linting
ruff check src/
# Type checking
mypy src/mockapi/
License
MIT License
Releases
1
v0.1.0 Initial Release
Latest
Languages
Python
100%