Swagger API mock server with fake data generation with main features.
- OpenAPI 3.x support.
- Load specification from local file or URL.
- JSON and YAML format supported.
- Generates fake response data by provided schemas.
- Content negotiation by Accept header.
- Runs in Docker container.
Feature | Support status |
---|---|
generating xml response | basic support (without xml tags) |
generating json response | supported |
generation of basic types | supported |
generation of enums | supported |
generation of associative arrays | supported |
generation of combined types | supported (without tag not and discriminator) |
local reference resolving | supported |
remote reference resolving | not supported |
URL reference resolving | not supported |
validating request data | not supported |
force using custom response schema | not supported (schema detected automatically) |
Recommended way is to use Docker container.
docker pull swaggermock/swagger-mock
# with remote file
docker run -p 8080:8080 -e "SWAGGER_MOCK_SPECIFICATION_URL=https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml" --rm swaggermock/swagger-mock
# with local file
docker run -p 8080:8080 -v $PWD/examples/petstore.yaml:/openapi/petstore.yaml -e "SWAGGER_MOCK_SPECIFICATION_URL=/openapi/petstore.yaml" --rm swaggermock/swagger-mock
Also, you can use Docker Compose. Example of docker-compose.yml
version: '3.0'
services:
swagger_mock:
container_name: swagger_mock
image: swaggermock/swagger-mock
environment:
SWAGGER_MOCK_SPECIFICATION_URL: 'https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml'
ports:
- "8080:8080"
To start up container run command
docker-compose up -d
Mock server options can be set via environment variables.
- Path to file with OpenAPI v3 specification (required)
- Possible values: any valid URL or path to file
- Error log level
- Default value:
warning
- Possible values:
error
,warning
,info
,debug
- Directory for OpenAPI specification cache
- Default value:
/dev/shm/openapi-cache
- Possible values: any valid path
- Time to live for OpenAPI specification cache in seconds
- Default value: 0
- Possible values: positive integer
- Caching strategy for OpenAPI specification cache
- Default value:
disabled
- Possible values:
disabled
,url_md5
,url_and_timestamp_md5
To speed up server response time you can use caching mechanism for OpenAPI. There are several caching strategies. Specific strategy can be set by environment variable SWAGGER_MOCK_CACHE_STRATEGY
.
url_md5
calculates hash from specification URL and if specification URL was not changed uses parsed objects from cache.url_and_timestamp_md5
calculates hash from specification URL and timestamp (file timestamp or value ofLast-Modified
header). If you are using file from remote server make sure that validLast-Modified
header is present.
Recommended options for use with remote file (accessible by URL).
SWAGGER_MOCK_CACHE_STRATEGY='url_md5'
SWAGGER_MOCK_CACHE_TTL=3600
Recommended options for use with local file (at local server).
SWAGGER_MOCK_CACHE_STRATEGY='url_and_timestamp_md5'
SWAGGER_MOCK_CACHE_TTL=3600
This project is licensed under the MIT License - see the LICENSE file for details.
- extra response negotiation (return of 405 code)
- path parser
- route matcher in path object
- routing by path and endpoints
- response cache
- faker expression extension for numbers
- faker expression extension for strings
- request body validation
- remote reference support
- url reference support
- discriminator in combined types