首页 > 其他分享 >Swagger 定义接口时参数定义案例

Swagger 定义接口时参数定义案例

时间:2023-03-05 20:34:53浏览次数:36  
标签:schema 定义 data number 接口 file Swagger type description

案例一:parameters + responses 

def square():
    """
    Calculate the square of a number.
    ---
    parameters:
      - name: number
        in: query
        type: number
        required: true
        description: The number to be squared.
    responses:
      200:
        description: The square of the input number.
        schema:
          type: object
          properties:
            result:
              type: number
              description: The square of the input number.
    """

案例二:上传两个文件

@BP.route('/upload', methods=['POST'])
def upload():
    """
    ---
   post:
       description:| \n
        Upload files \n
       consumes:
        - multipart/form-data
       produces:["application/json"]
       requestBody:
          content:
               multipart/form-data:
                 schema:
                     type:object
                     properties:
                        file1_name:
                            schema:
                                type:file
                                consumes:["mutipart/form-data"]
                            required:true
                            description: upload file file1_name
                            in:formData
                            type:file
                        file2_name:
                            schema:
                                type:file
                                consumes:["mutipart/form-data"]
                            required:true
                            description: upload file file2_name
                            in:formData
                            type:file

     responses:
         '200':
            description:call successful
            content:
                 application/json:
                     schema:UpLoadSchema
     tags:
            - upload functions

    """

案例三: 上传文件数组(多个文件)

@BP.route('/multifiles',methods=['POST']):
def  multifiles():
   """
   ---
   post:
      description: | \n
        Upload files \n
      consumes:
        -multipart/form-data
      produces:["application/json"]

      requestBody:
          required:true
          content:
              mutipart/form-data
                schema:
                    type:object
                    properties:
                        files:
                           type:array
                           items: 
                               type:string
                               format:binary
   """

 

标签:schema,定义,data,number,接口,file,Swagger,type,description
From: https://www.cnblogs.com/oceaning/p/17181539.html

相关文章