我是SwaggerUI的新手。在我的python代码中,我有一个名为'work'的API,它支持POST,PUT和DELETE HTTP方法。使用Swagger在相同def中使用HTTP方法的语法
现在我想创建相同的Swagger文档。我正在使用以下代码:
@app.route('/work', methods=['POST', 'PUT', 'DELETE'])
def work():
"""
Micro Service Based API for work operations
This API is for work to task matching operations
---
paths:
/cv:
put:
parameters:
- name: body
in: body
required: true
schema:
id: data
properties:
_id:
type: string
description: Id
responses:
200:
description: Please wait the calculation, you'll receive an email with results
delete:
parameters:
- name: body
in: body
required: true
schema:
id: data
properties:
_id:
type: string
description: Id
responses:
200:
description: Please wait the calculation, you'll receive an email with results
post:
responses:
200:
description: done
"""
但是,它似乎没有工作。
我试图浏览下面的文档链接,但不要太大的帮助 https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#pathsObject
能否请你帮我吗?
每个HTTP方法请求的参数都不同,我也希望为我的HTTP UI中的每个方法指定不同的描述。
编辑
将此添加到index.yml文件。
swagger: "2.0"
info:
description: "This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters."
version: "1.0.0"
title: "Swagger Petstore"
schemes:
- "http"
paths:
/work:
put:
tags:
- "WORK"
summary: "Update a Work Score"
description: ""
consumes:
- "application/json"
parameters:
- in: "body"
name: "body"
description: "Work ID whose score needs to be updates"
required: true
schema:
$ref: "#/definitions/Data"
responses:
200:
description: "Invalid input"
/scoreCompute:
post:
tags:
- "ABCD"
summary: "Compute ABCD"
description: ""
consumes:
- "application/json"
parameters:
- in: "body"
name: "body"
description: "Compute ABCD"
required: true
schema:
$ref: "#/definitions/TaskId"
responses:
200:
description: "Invalid input"
definitions:
Data:
type: object
properties:
_id:
type: string
description: Enter ID
TaskId:
type: object
properties:
job_id:
type: string
description: Enter ID
对python代码进行了上述修改。
@app.route('/work', methods=['POST', 'PUT', 'DELETE'])
@swag_from('index.yml')
def work():
但是http://127.0.0.1:5000/apidocs/#!/default/什么也没有显示。
如果你把你的yaml代码放在编辑器http://editor.swagger.io/#/中是什么意思? –
@ Dan-Dev您是否可以检查编辑部分,我已经添加了 – amankedia