如何在我的 YAML Swagger 定义中将属性类型定义为字符串列表(列表、集合、数组、集合) [英] How can I define a property type as being a list (list, set, array, collection) of string in my YAML Swagger definition

查看:29
本文介绍了如何在我的 YAML Swagger 定义中将属性类型定义为字符串列表(列表、集合、数组、集合)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个 API 编写一个 swagger 定义文件.该 API 用于 GET 请求

I am writing a swagger definition file for an API. The API is a for a GET request

/path/to/my/api:
  get:
    summary: My Custom API
    description: |
      Gets a List of FooBar IDs
    produces:
      - application/json
    tags:
      - FooBar
    responses:
      "200":
        description: successful operation
        schema:
          $ref: "#/definitions/MyCustomType"         

...

MyCustomType:
  type: object
  properties: 
    myCustomObject
      type: ??? # list of string?

推荐答案

对于字符串列表,可以这样描述:

For a list of strings, you can describe as follows:

      type: array
      items:
        type: string

参考:https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#schemaObject

例子:

  • https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/2_0/petstore.yaml#L93-L100 (OpenAPI v2)
  • https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml#L71-L78 (OpenAPI v3)

这篇关于如何在我的 YAML Swagger 定义中将属性类型定义为字符串列表(列表、集合、数组、集合)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆