Categorygithub.com/muonsoft/openapi-mock
module
0.3.9
Repository: https://github.com/muonsoft/openapi-mock.git
Documentation: pkg.go.dev

# README

OpenAPI Mock Server

CI GitHub release (latest by date) Scrutinizer Code Quality Maintainability Test Coverage

OpenAPI API mock server with random data generation by specified schemas.

  • OpenAPI 3.x support.
  • Load specification from a local file or URL.
  • JSON and YAML format supported.
  • Generates fake response data by provided schemas or by examples.
  • Content negotiation by Accept header.
  • Can be used as standalone application (Linux and Windows) or can be run via Docker container.

Supported features

FeatureSupport status
generating xml responsebasic support (without xml tags)
generating json responsesupported
generation of basic typessupported
generation of enumssupported
generation of associative arrayssupported
generation of combined typessupported (without tag not and discriminator)
local reference resolvingsupported
remote reference resolvingnot supported
URL reference resolvingnot supported
validating request datanot supported
force using custom response schemanot supported (schema detected automatically)

Quick start

Download latest binary and run a server.

# runs a local server on port 8080
./openapi-mock serve --specification-url https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml

# to test that the server successfully ran
curl 'http://localhost:8080/v1/pets'

Alternatively, you can use Docker image.

# downloads an image
docker pull muonsoft/openapi-mock

# runs a docker container with exported port 8080
docker run -p 8080:8080 -e "OPENAPI_MOCK_SPECIFICATION_URL=https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml" --rm muonsoft/openapi-mock

# to test that the server successfully ran
curl 'http://localhost:8080/v1/pets'

Also, you can use Docker Compose. Example of docker-compose.yml

version: '3.0'

services:
  openapi_mock:
    container_name: openapi_mock
    image: muonsoft/openapi-mock
    environment:
      OPENAPI_MOCK_SPECIFICATION_URL: 'https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml'
    ports:
      - "8080:8080"

To start up a container run command.

docker-compose up -d

If you want to reference a local file in docker compose:

  • you must first mount the host dir into container - ./openapi:/etc/openapi
  • only then can you reference it
version: '3.0'

services:
  openapi_mock:
    container_name: openapi_mock
    image: muonsoft/openapi-mock
    volumes:
    - ./openapi:/etc/openapi
    environment:
      OPENAPI_MOCK_SPECIFICATION_URL: '/etc/openapi/petstore.yaml'
    ports:
      - "8080:8080"

Usage guide

License

This project is licensed under the MIT License - see the LICENSE file for details.

# Packages

No description provided by the author
No description provided by the author
No description provided by the author