How to pass RAML-trait-parameters for enum values?


#1

I do have a RAML with several traits and recourceTypes. I do use the parameters there quite frequently. However, for one case I can’t get it working.

Let’s assume the following trait, named “testTrait”:

#%RAML 1.0 Trait

queryParameters:
  s:
    type: array
    items:
      type: string
      enum: <<parameterEnum>>

The enum: parameterEnum>> is the important part here.

This is used, beside many other working traits wich I don’t mention here to keep the example simple, in the following resourceType (which shoulnd’t have an influence on the issue, as I do simply pass the parameter through).

#%RAML 1.0 Library

...

resourceTypes:
  item-readonly:
      get:
        description: |
          <<descriptionGet>>
        is: [
          testTrait: {
            parameterEnum: <<parameterEnum>>
            }]

In this way, the trait “testTrait” is used in the API definition:

#%RAML 1.0

...

/services/:
  /testServiceA/:
    type:
      ResourceTypes.item-readonly:
        descriptionGet: A service to test Enum parameters in RAML.
        parameterEnum: ???

What should I fill in for the ‘???’ ?

I tested:

parameterEnum: [key,name]

Which resulted in error: "Property ‘parameterEnum’ must be a string"
Changing to:

parameterEnum: "[key,name]"

leads to the error: "‘enum’ facet value must be defined by array"
I’m stuck at this point. For other trait-parameters (as in description, for types etc.) I didn’t have any problem.
Any advice to point me to the right solution is appreciated.

I use Atom with API Workbench for the API definition.

Thanks for your help in advance!

Sitenote:
In my tries I also discovered, that after a parameter in the service definitioen there are no multi line elements allowed, so folowing example. Is this true or am I missing a thing?
For example, this is not working:

/services/:
  /testServiceB/:
    type:
      ResourceTypes.item-readonly:
        descriptionGet: A service to test Enum parameters in RAML.
        parameterXYZ:
          type: object
          properties:
            test1:
              type: boolean
            test2:
              type: string

#2

Unfortunately, only scalar values are currently supported to pass as parameter. What I would suggest is to create an enhancement request on the specification since I think it is a good candidate.


#3

I did an enhancement request:
https://github.com/raml-org/raml-spec/issues/608