Use traits to add mime-type to Accept header and add matching response


#1

Hi,

Am trying to add support for another mime-type through a trait, but the way I’m attempting this results in both the “API Console” in Atom’s APi Workbench, as well as under Resources in the online Mulesoft API Designer the the company/{id} resource doesn’t show anymore.

If I remove the is: [Printable] on the last line of my RAML file, the tools mentioned above start showing the /{id} endpoint again, but of course my /companies/{id} endpoint won’t be ‘printable’

So questions:

  • Am I doing it wrong?
  • or am I trying to do something that is not possible?
  • or are both tools buggy in the same way?

Here’s my RAML:

#%RAML 1.0
title: test
version: v1
baseUri: http://api.samplehost.com
traits:
  Printable:
    headers:
      Accept:
        type: string
        enum: [application/pdf]
    responses:
      200:
        body:
          application/pdf:
              type: file
resourceTypes:
  Collection:
    get:
      headers:
        Accept:
          enum: [application/json]
          default: application/json
      responses:
        200:
          body:
            application/json:
              type: <<item>>[]
  Member:
    get:
      headers:
        Accept:
          enum: [application/json]
          default: application/json
      responses:
        200:
          body:
            application/json:
              type: <<item>>
types:
  BaseEntity:
    properties:
      id: string
  ReferenceEntity:
    type: BaseEntity
    properties:
      types:
        type: array
        items: string
      status:
        enum: [ ACTIVE, INACTIVE ]
  Company:
    type: ReferenceEntity | file

/companies:
  type: { Collection: {item: Company} }

  /{id}:
    type: { Member: {item: Company} }
    is: [Printable]

#2

MH, are you sure that it is not working?

I have tried in inside MuleSoft’s Anypoint Platform API designer and it works:


#3

Mmm, dunno why, but indeed it now shows.

I do have another problem/challenge related to this now, but I’ll post that in it’s own topic

Tnx for having a look