4

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

0

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.