int*_*cho 4 swagger-ui swagger-2.0 swagger-editor
我定义了一个以MyObject作为参数的路径。MyObject具有猫和狗的属性。这些具有默认值。在swagger-editor中,该示例未显示默认值,但是try-it-out确实创建了具有正确默认值的MyObject。
在swagger-ui中,我可以在“模型”下看到默认值,但在API中看不到。有没有办法设置这些默认值?招摇:'2.0'信息:标题:传递带有默认属性的对象作为参数描述:等版本:“草稿0.1.1”主机:example.com basePath:/产生:-application / json
paths:
/myobject:
post:
summary: |
post an object.
parameters:
- name: myObject
in: body
required: true
schema:
type: array
items:
$ref: '#/definitions/MyObject'
responses:
200:
description: OK
definitions:
MyObject: # move to/models/model.yml
type: object
description: Contains default properties
required:
- cats
- dogs
properties:
cats:
type: number
default: 9
dogs:
type: string
default: "fido"
Run Code Online (Sandbox Code Playgroud)
您对的使用default是错误的。您可能想要example代替。
default仅用于可选字段,并在服务器端处理。也就是说,如果客户端未在有效负载中提供值,则服务器将使用该default值。
考虑以下User模型:
definitions:
User:
type: object
required:
- username
properties:
username:
type: string
role:
type: string
enum:
- user
- poweruser
- admin
default: user
Run Code Online (Sandbox Code Playgroud)
该role属性是可选的,默认为user。因此,如果客户端发送的有效载荷没有role:
{
"username": "bob"
}
Run Code Online (Sandbox Code Playgroud)
服务器将假定role= user。
就您而言,您似乎想为这些字段提供示例值。这是example关键字的意思:
definitions:
MyObject:
type: object
description: Contains default properties
required:
- cats
- dogs
properties:
cats:
type: number
example: 9 # <---
dogs:
type: string
example: fido # <---
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9088 次 |
| 最近记录: |