Developing Flask API Interface Help documentation with the Swagger module

Source: Internet
Author: User

The swagger website calls it the world's most popular API tool. Used to say yes. I've had a deep feeling.

Attach the website edit page. Only need to copy the corresponding files to achieve the effect

Swagger Online Editor

Here's a look at how to use this cock blast app in Python's flask framework.

1. Install Flasgger Project Address Https://github.com/rochacbruno/flasgger

Pip Install Flasgger

2. Write a simple Web example.


650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M02/05/A9/wKiom1mpCKCj1WTsAAD3Y0f5wUA218.png-wh_500x0-wm_ 3-wmp_4-s_591648370.png "title=" Clipboard.png "alt=" Wkiom1mpckcj1wtsaad3y0f5wua218.png-wh_50 "/>

Here is the shorthand code

#coding: Utf8import sysreload (SYS) sys.setdefaultencoding (' UTF8 ') from flask import Flask,blueprint,render_template, Request,redirect,jsonifyfrom Flasgger Import Swagger,swag_fromapp = Flask (__name__) Swagger = Swagger (APP) # Swagger Show API interface method collection, Access http://127.0.0.1:9001/apidocs/can @app.route ('/api/publish/k8sbuildjob/', methods=[' POST ') @ Swag_from (' apidescymal/color.yml ') def build (): Return jsonify ({}) if __name__ = = ' __main__ ': App.run (host= ' 0.0.0.0 ', p Ort=9001,debug=true)

3, description file. Example Color.yml

Publish the Color.yml file specified by the Image compilation task interface---schemes:  - httpparameters:  - name: appid     in: body    description:  Specify the appid    for which the image needs to be compiled  type: integer    enum: [' 111 ',  ' 222 ',]     required: true    default: all  - name: dbenv     in: body    description:  Specify database DB environment     type:  string    enum: [' formal ',  ' test ']    required:  True    default: all  - name: dbname    in:  body    description:  Specifying Database db    type: string     enum: [' kubernetes ',  ' Cdsmdb ']    required: true     default: all   - name: releaseenv    in: body    description:   Release Environment     type: string    enum: [' Test ',  ' Pro '     required: true    default: alldefinitions:   palette:    type: object    properties:       palette_name:        type: array         items:           $ref:  ' #/ Definitions/k8sbuildjob '   color:    type: stringresponses:  200:     description:  return is a tuple, the first bit is the status code 0 successful, 1 failed, the second is a success or failure information     schema:        $ref:  ' #/definitions/k8sbuildjob '     examples:       data:  (0,  "send rabbitmq k8s job success") 

4. Running the program

Python k8sdashboard.py

To access the API Help interface:

The default interface is:

Http://172.31.29.123:9001/apidocs/#/default

650) this.width=650; "Src=" https://s1.51cto.com/wyfs02/M01/05/AA/wKiom1mpCrSxYixtAAJBLuf0s1w187.png-wh_500x0-wm_ 3-wmp_4-s_487347683.png "title=" Xxxxxx.png "alt=" Wkiom1mpcrsxyixtaajbluf0s1w187.png-wh_50 "/>

For more information, visit the official website for self study

This article is from the "people on the Run" blog, please be sure to keep this source http://leizhu.blog.51cto.com/3758740/1961946

Developing Flask API Interface Help documentation with the Swagger module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.