如何在 Raml 的外部文件中定义一个类型的数组? [英] How to define an array of a type in an external file in Raml?

查看:44
本文介绍了如何在 Raml 的外部文件中定义一个类型的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个定义数据类型 SimpleDuple 的文件,并且在另一个文件中定义另一个名为 DiscreetFilter 的数据类型,我想要一个属性 values成为 SimpleDuple 的数组,我将如何在其中使用包含?

If I have a file defining a Datatype SimpleDuple, and in another file defining another datatype called DiscreetFilter I want to have a property values to be an array of SimpleDuple how would I use include there?

考虑 SimpleDuple 的文件:

Consider the files for SimpleDuple:

#%RAML 1.0 DataType
type: object
properties:
  id: string
  name: string

而我想要创建属性的另一个定义是 values 属性中的 SimpleDuples 数组(但我必须使用内联定义).

And the other definition where I want to make a property be an array of SimpleDuples in the values property (but I had to use an inline definition).

#%RAML 1.0 DataType
type: object
properties:
  field: string
  name: string
  type: { enum: [ discreet ] }

  # Ideally this property would use an include
  # in some way to express the equivalent of SimpleDuple[]
  values: 
    type: array
    properties:
      id: string
      name: string

如果这两种类型在同一个文件中,我会将 values 属性设置为 SimpleDuple[].如果它不是一个数组,我会将包含作为 values 属性的值.

If those two types where on the same file I'd set the values property to SimpleDuple[]. If it wasn't an array I'd put the include as the value of the values property.

但是如何同时使用包含和数组,而不是使用我在复制代码中使用的内联定义?

But how do I use an include and an array at the same time instead of using the inline definition I used in the copied code?

推荐答案

你应该能够做到以下几点:

You should be able to do the following:

chapter.raml

#%RAML 1.0 DataType

type: object
properties:
  name: string

storyboard.raml

#%RAML 1.0 DataType

type: object
properties:
  name: string
  chapters:
    type: array
    items: !include chapter.raml

希望有帮助吗?!

这篇关于如何在 Raml 的外部文件中定义一个类型的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆