How can I define a property type as being a list (list, set, array, collection) of string in my YAML Swagger definition

扶醉桌前 提交于 2019-12-19 17:41:01

问题


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?

回答1:


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

      type: array
      items:
        type: string

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

Example:

  • 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)


来源:https://stackoverflow.com/questions/38553582/how-can-i-define-a-property-type-as-being-a-list-list-set-array-collection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!