Skip to content

katakonst/swagger-mock

Repository files navigation

Generate mock server from swagger spec

This tool generate a mock-server from a swagger spec

Perequisites

  • Install Golang
  • Run go get . in swagger-mock directory

Build

$ ./build.sh

Will copy files to template folder and build swagger-mock executable

Usage

Generate Go Sources

This will generate go sources in source folder

$ ./swagger-mock -spec=test.yml -out=sources  -rule=rules.json -host=localhost:9000

Run Embedded server

This will start the embedded server

$ ./swagger-mock -spec=spec.yml  -rule=rules.json -host=localhost:9000 -embedded=true

Download executables

Download

Config

Example

{
  "rules": [
    {
      "opId": "createPets",
      "method" : "POST",
      "timeout": "10s",
      "statusCode":201,
      "args": [{
        "argType": "JSON",
        "body":{"id":"1"}
      }],
      "response":
        {
          "id":"3",
          "name": "4"
        }
      
    }
  ]
}

This will serve the response for a request for the path from createPets operation id if the request body is {"id":"1"}. In the repo exists a rule.json and a spec.yml for testing

About

Generate a mock server from a swagger spec

Resources

Stars

Watchers

Forks

Packages

No packages published