Search code examples
swaggerswagger-uidoclet

Is it possible to generate a mock implementation based on static swagger service.json?


I am generating the swagger service.json and other resource.jsons during the maven build cycle via the Carma swagger-jaxrs-doclet. Afterwards, I deploy the artifacts, together with swagger-ui on a webserver, and I can consult the generated documentation. This means that I am not deploying a swagger bean with my application!

Since swagger is mostly deployed along your API implementation, I was wondering which approach swagger-ui takes to make the docs executable. Does it redirect from the swagger-ui docs to the real implementation, or does it create a mock-backend, based on the service.json? I have read that it is possible to create a backend in node.js, based on the service.json, but I can't figure out how to do it in the web page. I even do not now if it is possible from within the webpage?


Solution

  • Swagger-ui reads the swagger specifications you expose and exposes an html application that allows you to execute the API that is documented. It doesn't create a backend, it uses the swagger-js project to dynamically read the specification and execute the calls.

    So for javascript based applications, you have swagger-js, but otherwise if you want to generate clients you can use swagger-codegen - https://github.com/wordnik/swagger-codegen - which reads the specification files you have and allows you to perform various tasks like create clients, servers, static docs and so on.