I have rest api developed using Bottle. Is there any library like swagger-ui which helps to view the documentation and test the apis?
2 Answers
In order to setup swagger documentation for Bottle based rest services: Copy swagger UI files to web container
- You need swagger UI specific web content files hosted on a web server.
Clone https://github.com/swagger-api/swagger-ui.git and copy "dist" folder contents to your web container docs resources directory.
For example, if you copy the dist folder contents to docs directory under your bottle project root folder, add the below method to your Bottle Instance to route the requests appropriately.
@app.get('/docs/<filename:re:.*>')
def html(filename):
return static_file(filename, root='docs/')
**Below step is applicable to rest services on any platform. However few frameworks (Java Jersey or Flask) have the below functionalities built-in. Edit the json file
- Edit index.html from the files you copied. This file has a link to the rest service documentation json (to be loaded/parsed by swagger)
i.e change the below line in index.html to refer to json file which contains the rest service documentation in swagger structure.
url = "http://petstore.swagger.io/v2/swagger.json";
As a starting point for this json refer to http://petstore.swagger.io/v2/swagger.json
That's all we need. Launch
http://<hostname:port>/<path for swagger resources>/index.htmlto view swagger docs.
Comments
There is not auto documenting tool for Bottle to generate Swagger REST definition. There are too many web frameworks in python, it's not efficient to write one for each. My suggestion is to use swagger-editor to write Swagger REST definition in yaml, which is easier than writing in json directly.
For unittest, you can try pyswagger, which is a tool I wrote for testing Swagger enabled REST service in python.