Add all source files for CI to work
Some checks failed
CI / test (push) Has been cancelled
CI / build (push) Has been cancelled

This commit is contained in:
2026-03-22 21:22:40 +00:00
parent a859ed67cb
commit d0cf0e3711

141
README.md
View File

@@ -1,83 +1,45 @@
# MockAPI
# MockAPI - OpenAPI Mock Server Generator
OpenAPI Mock Server Generator - Generate functional mock APIs from OpenAPI 3.x specifications.
A CLI tool that generates a fully functional mock API server 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`
- Generate mock server from OpenAPI 3.x specs
- Configurable response delays and error simulation
- Random realistic test data generation from schemas
- Request validation against OpenAPI spec
- Hot-reload on spec changes
- Built-in random data generators for common types
## Installation
```bash
pip install -e .
```
Or install from source:
```bash
git clone https://7000pct.gitea.bloupla.net/7000pctAUTO/mockapi.git
cd mockapi
pip install -e ".[dev]"
pip install -e .[dev]
```
## Quick Start
```bash
# Validate an OpenAPI spec
mockapi validate examples/petstore.yaml
mockapi validate openapi.yaml
# Start a mock server
mockapi start examples/petstore.yaml
mockapi start openapi.yaml
# Generate a summary
mockapi generate examples/petstore.yaml
# Show configuration
mockapi show-config
```
## CLI Commands
### validate
Validate an OpenAPI specification file:
```bash
mockapi validate spec.yaml
```
### start
Start a mock server from an OpenAPI spec:
```bash
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:
```bash
mockapi generate spec.yaml
```
### show-config
Show current configuration:
```bash
mockapi show-config
```
- `validate` - Validate an OpenAPI specification file
- `start` - Start a mock API server from an OpenAPI specification
- `generate` - Generate code/structure from an OpenAPI spec (dry-run mode)
- `show-config` - Show the current configuration
## Configuration
Create a `mockapi.yaml` file to configure mock behavior:
Create a `mockapi.yaml` file:
```yaml
port: 8080
@@ -86,73 +48,8 @@ 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 port
- `MOCKAPI_HOST`: Override default host
- `MOCKAPI_SEED`: Override random seed
## Hot Reload
Enable automatic server restart when the spec file changes:
```bash
mockapi start spec.yaml --watch
```
## Request Validation
By default, incoming requests are validated against the OpenAPI spec. Disable with:
```yaml
validate_requests: false
```
## Error Simulation
Use the `x-mock-config` extension in your OpenAPI spec:
```yaml
paths:
/users:
get:
x-mock-config:
errorProbability: 0.1
errorCode: 500
errorMessage: "Service unavailable"
```
## Development
```bash
# 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
MIT