【发布时间】:2017-10-04 04:35:59
【问题描述】:
我有一个模型定义为:
Event:
type: object
properties:
id:
type: string
timestamp:
type: string
format: date-time
type:
type: string
enum:
- click
- open
- sent
click:
type: object
properties:
url:
type: string
title:
type: string
open:
type: object
properties:
subject:
type: string
sent:
type: object
properties:
subject:
type: string
from:
type: string
to:
type: string
但是,形状实际上是不同的,具体取决于type 枚举字段的值。它可以是三个之一,我试图在examples 中定义差异(见下文),但这不起作用。
如您所见,下面显示了三个示例,每个示例都因type 而不同。这就是 API 的行为方式,但记录这种预期行为并不简单。
examples:
application/json:
- id: >
ad1b12f0-63a8-47b5-9820-3e447143ce7e
timestamp: >
2017-09-29T16:45:20.000+00:00
type: click
click:
url: >
www.some-website-somewhere.org/12345
title: >
Click here!
- id: >
d9e787fa-db49-4bd8-97c3-df45f159295c
timestamp: >
2017-09-29T16:45:20.000+00:00
type: open
open:
subject: >
Have you seen this?
- id: >
30adc194-0f5f-4889-abd4-4fa964d0bb42
timestamp: >
2017-09-29T16:45:20.000+00:00
type: sent
sent:
subject: >
Have you seen this?
from: >
bill@office.gov
to: >
mon@gmail.com
我读过一些地方提到这是不可能的,但我希望能得到一些“跳出框框”的思想家来帮助我找到解决方案。
【问题讨论】:
-
在您的第二个示例中,标量的每个折叠样式指示符 (
>) 都是多余的,并且使您的 YAML 不必要地不可读。那是因为这些标量都不是由多行组成的,而且对于其中许多甚至是不可能的。这是关于如何不执行 YAML 的一个很好的例子 -
很公平。对实际问题没有帮助?
-
我对swagger一无所知,我是因为(IMO放错位置)yaml标签而来到这里的。
标签: swagger swagger-2.0