Jac*_*ler 30 swagger swagger-editor
所以我理解,如果我们想要身体参数,我们必须有一个模式,我这样做.问题是无论我如何尝试定义我的架构,它都不允许我有多个body参数.这是我尝试过的方法之一的示例.任何帮助都会很棒!
swagger: '2.0'
# This is your document metadata
info:
version: "0.0.1"
title: Todo App
schema: {
}
host: localhost:3000
schemes:
- http
- https
consumes:
- application/json
produces:
- application/x-www-form-urlencoded
basePath: /
paths:
# This is a path endpoint. Change it.
/tasks:
post:
description: |
Add 'Task' object.
parameters:
# An example parameter that is in query and is required
-
name: name
in: query
description: unique object task name
required: true
schema:
type: string
- name: description
in: query
description: task description
required: true
schema:
type: string
responses:
# Response code
200:
description: Successful response
# A schema describing your response object.
# Use JSON Schema format
schema:
title: Return String
type: string
example: "Task added succesfully"
500:
description: Error
schema:
type: string
example: "Could not add Task"
Run Code Online (Sandbox Code Playgroud)
Nel*_* G. 38
我不确定你理解你的问题......
Body [...]只能有一个body参数
您的示例节点也是错误的,请参阅此处了解更多详细信息.
swagger: '2.0'
info:
version: "0.0.1"
title: Todo App
host: localhost:3000
schemes:
- http
- https
consumes:
- application/json
produces:
- application/x-www-form-urlencoded
basePath: /
paths:
# This is a path endpoint. Change it.
/tasks:
post:
description: |
Add 'Task' object.
parameters:
- name: task
in: body
description: task object
required: true
schema:
$ref: '#/definitions/Task'
responses:
200:
description: Successful response
schema:
title: Return String
type: string
example: "Task added succesfully"
500:
description: Error
schema:
type: string
example: "Could not add Task"
definitions:
Task:
description: Task object
properties:
name:
type: string
description: task object name
description:
type: string
description: task description
required:
- name
- description
Run Code Online (Sandbox Code Playgroud)
您还可以将请求主体参数的属性定义properties为schema。这在对象有效负载下有一个很好的示例:https : //swagger.io/docs/specification/2-0/describing-request-body/。
paths:
/users:
post:
summary: Creates a new user.
consumes:
- application/json
parameters:
- in: body
name: user
description: The user to create.
schema:
type: object
required:
- userName
properties:
userName:
type: string
firstName:
type: string
lastName:
type: string
responses:
201:
description: Created
Run Code Online (Sandbox Code Playgroud)
当然,缺点是您无法重用对象定义,但是有时对象定义不合适。
| 归档时间: |
|
| 查看次数: |
57757 次 |
| 最近记录: |