This add-on integrates OpenAPI Mock into your DDEV project to easily test and interact with a fake OpenAPI interface.
For an integrated OpenAPI documentation, the Swagger UI is also available.
ddev add-on get jackd248/ddev-openapi-mock
ddev restart
After installation, make sure to commit the .ddev
directory to version control.
By default, the OpenAPI petstore specification is used for demo purpose.
Tip
You can change the location of the OpenAPI specification by setting an DDEV environment variable. See the Advanced Customization section below for more details.
Regarding your used OpenAPI specification, you can use the following commands to interact with the OpenAPI Mock service, e.g. list all pets:
# List all pets
ddev launch :8080/v1/pets
# Open Swagger UI
ddev launch :8081
To change the Docker image:
ddev dotenv set .ddev/.env.openapi-mock --openapi-mock-specification="file:/data/openapi.json"
ddev restart
Make sure to commit the .ddev/.env.openapi-mock
file to version control.
All customization options (use with caution):
Variable | Flag | Default |
---|---|---|
OPENAPI_MOCK_DOCKER_IMAGE |
--openapi-mock-docker-image |
muonsoft/openapi-mock:latest |
OPENAPI_MOCK_PORT |
--openapi-mock-port |
8080 |
OPENAPI_MOCK_SPECIFICATION |
--openapi-mock-specification |
https://raw.githubusercontent.com/muonsoft/openapi-mock/refs/heads/master/examples/petstore.yaml |
OPENAPI_MOCK_USE_EXAMPLES |
--openapi-mock-use-examples |
if_present |
OPENAPI_MOCK_CORS_ENABLED |
--openapi-mock-cors-enabled |
true |
Note
If you’re using a local OpenAPI specification file, make sure to adjust the OPENAPI_MOCK_SPECIFICATION
variable accordingly, e.g. file:/data/openapi.json
.
Don’t forget to update the OPENAPI_SWAGGER_SPECIFICATION
variable to a similar value, otherwise the Swagger UI will not work properly.
To change the Swagger UI Docker image:
ddev dotenv set .ddev/.env.swagger-ui --openapi-swagger-specification="/data/openapi.json"
ddev restart
Make sure to commit the .ddev/.env.swagger-ui
file to version control.
All customization options (use with caution):
Variable | Flag | Default |
---|---|---|
OPENAPI_SWAGGER_SPECIFICATION |
--openapi-swagger-specification |
https://raw.githubusercontent.com/muonsoft/openapi-mock/refs/heads/master/examples/petstore.yaml |
Note
If you’re using a local OpenAPI specification file, make sure to adjust the OPENAPI_SWAGGER_SPECIFICATION
variable accordingly, e.g. /data/openapi.json
.
Contributed and maintained by @jackd248