Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swagger-UI like rest api documentation for python apis using Bottle

Tags:

bottle

I have rest api developed using Bottle. Is there any library like swagger-ui which helps to view the documentation and test the apis?

like image 752
suman j Avatar asked Oct 22 '25 17:10

suman j


1 Answers

In order to setup swagger documentation for Bottle based rest services: Copy swagger UI files to web container

  1. 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

  1. 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.html 
to view swagger docs.
like image 114
suman j Avatar answered Oct 27 '25 03:10

suman j



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!