How to reference mediaType in traits?


#1

Hello,

I defined the mediaType property explicitly in main raml file, and separate the traits definition in another file (called ‘common-traits.yml’), there I defind a Content-Type header, I expected I can reference the mediaType in example property of Content-Type header directly, but it seems doesn’t work, Could you give me some suggestion please?

Thanks,
Steward


#2

Can you elaborate more on what you try to achieve, maybe with an example please.


#3

Thank you for the reply!

Here is the main raml file:

#%RAML 0.8
title: Test
baseUri: https://api.test.com/{version}
version: v1
protocols: [HTTPS]
mediaType: application/com.test.v1+json

schemas:

  • !include common-schema.yml

traits:

  • !include common-traits.yml

resourceTypes:

  • !include all-resource-types.yml

/testSamples:
type: collection

Here is the common-traits.yml

customAndAcceptHeaders:
  headers:
    Accept:
      type: string
      required: true
      description: Media type for <<resourcePathName|!singularize>>.
      example: **mediaType**
    X-Realm:
      description: Realm id.
      required: true
      type: string
    X-Requestor:
      description: Requestor cuid.
         {person} must be prefixed to the requestor cuid
      required: true
      type: string
    X-Requestor-App:
      description: Application id the requestor belongs to.
      required: true
      type: string

I want to reference the mediaType in example property.

Thanks,
Steward