为什么请求主体没有显示在Flask Swagger UI中?

2024-09-28 23:30:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用flasgger库编写API文档:

@bp.route('/long_to_short', methods=['POST'])
def long_to_short():
    '''Create a short URL
    ---
    tags:
        - long_to_short
    requestBody:
        content:
            application/json:
                schema:
                    type: array
                    items:
                        long_url: https://google.com
        required: true

    '''

但UI不显示有关请求正文的信息: swagger ui 如何正确编写文档以使其正确显示


Tags: to文档apiurldefcreatetagspost
2条回答

以下是有效的标记:

@bp.route('/long_to_short', methods=['POST'])
def long_to_short():
    '''Create a short URL
     -
    tags:
        - long_to_short
    requestBody:
        content:
            application/json:
                schema:
                    $ref: '#definitions/Shortener'
    definitions:
        Shortener:
            type: object
            required:
                - long_to_short
            properties:
                long_to_short:
                    type: string
                    example: https://google.com
    '''

希望这对你有用

   tags:
   - long_to_short
   consumes:
   - "application/json"
   parameters:
   - in: "body"
     name: "body"
     required: true
     schema:
       type: "array"
       items:
        type: "object"
        properties:
         long_url:
         type: "string"
         example: "https://google.com"

相关问题 更多 >