RAML:表示具有固定枚举值的URL参数

时间:2017-06-19 10:46:31

标签: api raml

在我的RAML 1.0规范中,我想表示uriParameter,其值是枚举标记的集合列表之一。例如,_format只能是:csvjsonttl中的一个。

据我阅读RAML规范可以看出,除非我包含JSON模式声明,否则目前不可能。 RAML可以编码没有JSON模式的枚举,如果是,那怎么办?

1 个答案:

答案 0 :(得分:2)

Yes you can, by using RAML 1 data types:

"Data types can describe a base or resource URI parameter, a query parameter, a request or response header, or a request or response body. Data types are built-in or custom. A built-in type can be used anywhere the API expects data. Custom types can be defined by extending the built-in types as well as named and used like built-in type"

Example:

#%RAML 1.0
title: bla
types:
  foo:
    type: string
    enum: [ json, csv, ttl ]
/bar/{_format}:
  uriParameters:
    _format:
      type: foo
  get: