我正在尝试使用Swagger记录REST API . 根据REST API规范,我有每个 Thing
的 endpoints ,并且每个 endpoints 的GET协议都是标准的标准: /thing/{id}
返回一个带有您给出的匹配ID的 Thing
, /thing/
返回所有有效 Things
的列表 .
/thing/{id}
的YAML足够直截了当 .
get:
operationId: GET_thing-id
tags:
- Thing
description: >-
Gets a specific Thing.
parameters:
- name: token
in: query
required: false
type: string
- name: Accept
in: header
required: false
type: string
responses:
'200':
description: ''
schema:
$ref: '#/definitions/Thing'
$ref
引用以下内容,进一步向下YAML文件:
definitions:
Thing:
title: Thing
type: object
properties:
id:
type: string
description: uuid.
但我发现自己不确定如何处理 /thing/
endpoints ,它应该只返回上面模型的列表 . 似乎没有明确的方法来仔细阅读Swagger规范,我已经在这一点上做了深入的研究 . 有没有人有关于如何处理这个问题的指导?
1 回答
我想到了 . 问题是我需要为数组定义稍微不同的东西,这是跟踪它的一个真正问题 . 解决方案是:
然后可以在
/thing/
路径中使用它,它看起来非常合理 .