2
我想弄清楚如何使Swagger用户界面显示允许值的列表,而不是输入字段。Swagger用户界面参数列表,而不是文本输入
到目前为止,我能够让Swagger的不同版本和文档感到困惑。我不知道哪个是哪个(1.2,2.0,YAML,JSON ...)
到目前为止,这是我知道的:
- 有一些命令调用
allowableValues
但据我了解,它在Swagger 2.0中不可用 - 我发现了
enum
命令,但无法使它适用于我。 - 我不知道我是否应该在
parameters
部分定义了允许使用此值列表,或definitions
部分 - 我发现它确实有一个选择栏像我想要(GET/PET/findByTags)的petstore example,但就我所见到的“原始”JSON而言,它看起来像旧的Swagger格式。
最后,这里是我试图在this Swagger editor代码:
swagger: '2.0'
host: asd.com
schemes:
- http
info:
version: "1.0.0"
title: test
paths:
/users:
get:
parameters:
- name: status
in: query
type: string
enum:
- online
- offline
responses:
"200":
description: Nice
感谢您的详细回复。所以我想我现在应该使用1.2规范,如果我想要一个功能齐全的工具集?我在几个地方看到了allowableValues,并且由于我认为我的代码是错误的,所以可能会将它置于背景之外。示例:http://stackoverflow.com/questions/23936140/enum-in-swagger和 http:// stackoverflow。com/questions/14761424/using-servicestacks-swagger-plugin-how-to-implement -a-string-field-with-a-list – DannyB 2014-11-21 11:27:07
在swagger-ui和swagger-editor repos上发布的问题https:// github .com/swagger-api/swagger-ui/issues/736和https://github.com/swagger-api/swagger-editor/issues/256 – DannyB 2014-11-21 11:40:46
工具一直在进步,所以你可能真的想要坚持2.0,特别是如果你手动编写你的规格。 1.2没有这样的编辑器。感谢您打开这些问题。至于'allowableValues',第一个只是java实现,转化为'enum',第二个完全无效。 – Ron 2014-11-21 14:04:42