Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define an array of a type in an external file in Raml?

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?

Consider the files for SimpleDuple:

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

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

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?

like image 676
David Pelaez Avatar asked Jan 19 '16 20:01

David Pelaez


People also ask

How do you define a type in RAML?

You can define a type at the beginning of your RAML file, and you can later reference that same type to describe the body of as many API requests or responses as you need. You can even define a data type to inherit properties of another type within your API.

What is enum in RAML?

It's sometimes useful to define enumerated types such as: type: string. enum: [foo, bar] to restrict possible values that that type allows.

What is the keyword used to apply a library to a RAML specification?

Referencing a Library. A library is referenced by concatenating the library name, a dot (.), and the name of the element (e.g. data type, resource type, trait, etc) being referenced.


1 Answers

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

Hope that helps?!

like image 189
christian.vogel Avatar answered Sep 28 '22 23:09

christian.vogel