Passing a parameter to a trait inside a resource type
KevinMitchell opened this issue · 3 comments
Suppose I define the following trait (inside a library called traits):
hasResponseCollection:
responses:
200:
body:
application/json:
type: <<typeName>>[]
I can then define
/customers:
type: { collection: {typeName : Customer } }
get:
is:
- { traits.hasResponseCollection: {typeName : Customer } }
But I want to use this trait inside my resource type collection
. So inside this resource type I try
get:
is:
- { traits.hasResponseCollection: {typeName : <<typeName>> } }
and remove the reference to hasResponseCollection
from the get
method in /customers
. But when I view the documentation in API Designer the body of the 200 response has a Show Schema
button, and when this is pressed I get the text <<typeName>>[]
. So is this a problem with API Designer, am I using the wrong syntax here, or can parameters such as typeName
not be passed to other "calls"?
Hi @KevinMitchell ! Thanks for your report.
Will you please share the complete raml file and libraries to reproduce this ?
Regards
libraries/xtraits.raml:
#%RAML 1.0 Library
traits:
hasResponseCollection:
responses:
200:
body:
application/json:
type: <<typeName>>[]
libraries/xtypes.raml:
#%RAML 1.0 Library
types:
Customer:
properties:
id:
type: string
resources/xcollection.raml
#%RAML 1.0 ResourceType
uses:
traits: ../libraries/xtraits.raml
get:
is:
- { traits.hasResponseCollection: {typeName : <<typeName>> } }
Example.raml
#%RAML 1.0
title: xxx
version: '1.0'
protocols:
- HTTPS
uses:
traits: libraries/xtraits.raml
lib: libraries/xtypes.raml
resourceTypes:
collection: !include resources/xcollection.raml
/customers:
type: { collection: {typeName : lib.Customer } }
Viewing the response body I see <<typeName>>[]
Hope this helps,
Kevin
I've just realised I was picking up an older version of the API Designer by mistake. Trying the example on http://rawgit.com/mulesoft/api-designer it all behaves correctly. My apologies for the confusion.