问题
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