0

I am aware that swagger core , swagger inflector read a swagger.yaml / json file in creating a http response, Now we have a use wire mock to stub response where the content for the stub has to come from the swagger file.

I have gone through many examples but unable to figure out the right function to convert the swagger.yaml/json to return the http response. Please help me

  • 1
    Possible duplicate of [Swagger mock server](http://stackoverflow.com/questions/38344711/swagger-mock-server) – Helen Mar 27 '17 at 10:56

1 Answers1

0

SwaggerHub can be used to define your API in JSON or YAML. The UI provided alongside shows the API vividly. The UI has the option to trigger a newly defined API and check the response as a model - the structure of JSON response body. If "example" has been given in the API specification, it's fetched in the response.

If this response model works as per requirement, it can be then used in WireMock to generate stubbed responses having canned data. A swagger specification fragment and response model shown below -

API specification -

"swagger": "2.0",


    "info":{

    "version":"v0.1",

    "title":
    "Capital city finder",

    "description":"Search capital city by country name"

    },

    "definitions":{

    "city":{

    "properties":{

        "countryName":{

        "type":"string",

        "example":"United Kingdom"

        },

        "capitalCity":{

        "type":"string",

        "example":"London"

        },

        "nationalAnimal":{

        "type":"string",

        "example":"Lion"

        },

        "popularFood":{

        "type":"string",

        "example":"Fish & Chips"

        }

... ...  ...   

Response Model -


    [
      {
        "countryName": "United Kingdom",
        "capitalCity": "London",
        "nationalAnimal": "Lion",
        "popularFood": "Fish & Chips"
      }
    ]

Not sure if this is still relevant to you now.

kam
  • 26
  • 3