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 ## Features
- **OpenAPI 3.x Support**: Parse and validate OpenAPI specifications - Generate mock server from OpenAPI 3.x specs
- **Mock Server Generation**: Generate working mock servers using connexion - Configurable response delays and error simulation
- **Random Data Generation**: Create realistic test data from JSON schemas using Faker - Random realistic test data generation from schemas
- **Configurable Response Delays**: Simulate network latency with fixed or random delays - Request validation against OpenAPI spec
- **Error Simulation**: Simulate HTTP error responses for testing - Hot-reload on spec changes
- **Request Validation**: Validate incoming requests against OpenAPI spec - Built-in random data generators for common types
- **Hot-Reload**: Auto-restart server on spec file changes
- **YAML Configuration**: Configure mock behavior via `mockapi.yaml`
## Installation ## Installation
```bash ```bash
pip install -e . pip install -e .[dev]
```
Or install from source:
```bash
git clone https://7000pct.gitea.bloupla.net/7000pctAUTO/mockapi.git
cd mockapi
pip install -e ".[dev]"
``` ```
## Quick Start ## Quick Start
```bash ```bash
# Validate an OpenAPI spec # Validate an OpenAPI spec
mockapi validate examples/petstore.yaml mockapi validate openapi.yaml
# Start a mock server # Start a mock server
mockapi start examples/petstore.yaml mockapi start openapi.yaml
# Generate a summary # Show configuration
mockapi generate examples/petstore.yaml mockapi show-config
``` ```
## CLI Commands ## CLI Commands
### validate - `validate` - Validate an OpenAPI specification file
Validate an OpenAPI specification file: - `start` - Start a mock API server from an OpenAPI specification
```bash - `generate` - Generate code/structure from an OpenAPI spec (dry-run mode)
mockapi validate spec.yaml - `show-config` - Show the current configuration
```
### 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
```
## Configuration ## Configuration
Create a `mockapi.yaml` file to configure mock behavior: Create a `mockapi.yaml` file:
```yaml ```yaml
port: 8080 port: 8080
@@ -86,73 +48,8 @@ delay: 100
random_delay: false random_delay: false
seed: 42 seed: 42
validate_requests: true 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 ## License
MIT License MIT