转换 RAML 数据类型 XSD



Raml 网站声明我可以将 RAML 1.0 数据类型转换为 XML Schema:

数据类型

可以用来代替模式和示例,让你定义一种数据类型,然后可以动态转换为XML或JSON模式 - 让你简单地定义你的数据模型,让RAML负责REST。

我该怎么做?对具有继承和字符串模式的复杂类型的支持级别是什么?

该语句意味着您可以使用 XML 数据类型来定义复杂结构。此定义是合乎逻辑的,并且不指定物理格式,如 XML 或 JSON。

这是唱片集类型的定义:

#%RAML 1.0 DataType
type: AlbumSimple
displayName: Full Album Object
properties:
  artists: ArtistSimple[]  # would pull in ArtistSimple DataType
  copyrights: Copyright[]  # would pull in Copyright DataType
  external_ids: ExternalId  # would pull in ExternalId DataType
  genres:
    type: string[]
    description: |
      A list of the genres used to classify the album. If not yet classified,
      the array is empty.
    example: ["Prog Rock", "Post-Grunge"]
  popularity:
    type: integer
    description: |
      The popularity of the album. The value will be between 0 and 100,
      with 100 being the most popular. The popularity is calculated from
      the popularity of the album's individual tracks.
  tracks:
    type: Page  # would pull in Page DataType
    (pagedObject): TrackSimple
    description: The tracks of the album.

该定义并不意味着物理格式。您必须在正文内容类型中定义:

get:
      is: [ drm ]
      responses:
        201:
          body:
            application/json:
              type: AlbumSimple

最新更新