elo*_*eon 43 javascript json swagger
有没有人能够在swaggger 2.0版的Model选项卡中定义可能的'enum'值?示例:http : //petstore.swagger.wordnik.com/#!/pet/addPet具有"status"属性的枚举选项,但该示例使用的是swagger 1.0版(根据JSON对象中定义的swagger版本).我试图在版本2.0中实现相同但没有运气,不确定文档是否正确.
有什么暗示吗?
Ron*_*Ron 62
"enum"就像这样:
{
"in": "query",
"name": "sample",
"description": "a sample parameter with an enum value",
"type": "string",
"enum": [ "1", "2"],
"required": true
}
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,有一个名为sample
string类型的查询参数,并且有一个枚举表明两个可能的值.在这种情况下,示例声明参数是必需的,因此UI不会显示空值作为选项.
对于最小的工作样本,请尝试以下方法:
{
"swagger": "2.0",
"info": {
"title": "title",
"description": "descriptor",
"version": "0.1"
},
"paths": {
"/sample": {
"post": {
"description": "sample",
"parameters": [
{
"in": "query",
"name": "sample",
"description": "a sample parameter with an enum value",
"type": "string",
"enum": [
"1",
"2"
],
"required": true
}
],
"responses": {
"200": {
"description": "Successful request."
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
要在本地测试它,您可以spec
在javascript中声明一个变量(例如),并将其传递给SwaggerUi对象.
var spec = { ... };
window.swaggerUi = new SwaggerUi({
url: url,
spec: spec,
dom_id: "swagger-ui-container",
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
onComplete: function(swaggerApi, swaggerUi){
...
Run Code Online (Sandbox Code Playgroud)
url
在这种情况下,该参数将被忽略.
最终,输出如下所示:
我能够以这种方式做到这一点,但是你可以在下面的图片上看到每个参数创建了下拉列表:
我想要实现的是不错的模型/模型模式选项卡,如下图所示,并为参数列出了可用的枚举.在最新版本的Swagger中是否可以:
Ric*_*uza 13
使用YAML语法更新此内容:
in: query
name: sample
description: a sample parameter with an enum value
type: string
enum:
- 1
- 2
required: true
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
59604 次 |
最近记录: |