【问题标题】:Correct way to define an array of one or more strings using the OpenAPI v3 Specification [duplicate]使用 OpenAPI v3 规范定义一个或多个字符串数组的正确方法 [重复]
【发布时间】:2018-06-03 07:49:56
【问题描述】:

我希望 POST 一个包含可变数量字符串的数组,例如

["string1", "string2", ... "stringN"]

我目前的 OpenAPI 文档是这样定义的:

schema:
  type: array
    items:
      description: networkIds
      type: string

这是编写 OpenAPi v3 规范的正确方法,还是有更精确的方法来指示数组中的一个或多个字符串?

【问题讨论】:

    标签: arrays swagger openapi


    【解决方案1】:

    缩进错误 - typeitems 必须在同一级别。

    如果数组不能为空并且总是至少有 1 项,则可以添加 minItems: 1 作为附加约束。如果所有项目都必须是唯一的,请添加uniqueItems: true

    schema:
      type: array
      items:
        description: networkIds
        type: string
      minItems: 1
    

    【讨论】:

    • 谢谢你,海伦。这回答了我的问题。而且,是的,我应该在提交问题之前发现缩进问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-17
    • 1970-01-01
    相关资源
    最近更新 更多