Using trait parameter in both Get and Post


#1

I have few parameters that appear across different methods [mix of GET and POST methods]. I’m using traits to capture these params. But I’m ending up repeating these once for GET and once for POST. Is there a notation to refer to parameters of a trait in both Get and Post method without declaring them twice.

As an example, If I use a trait as “member_aware” to indicate the method invocation needs a valid member_id as:
trait:

  • member_aware:
    queryParameters:
    member_id:
    required: true
    description: |
    Id of the user
    currently this can be used only with GET, for post i’m redefining above with a different name ‘member_aware_post’.

#2

Hi @jestr,

what do you mean by that? Where do you get the error? It is working for me with the following snippet:

traits:
  - member_aware:
      queryParameters:
        member_id: 
          required: true 
          description: |
            Id of the user

/resource:
  get:
    is: [ member_aware ]
  post:
    is: [ member_aware ]

You can also define:

traits:
  - member_aware:
      queryParameters:
        member_id: 
          required: true 
          description: |
            Id of the user

/resource:
  is: [ member_aware ]
  get:
  post:

#3

Thanks for the quick reply…Yes, I’ve already tried what you suggested …and it works. But if you notice, in the right rail of API Designer where it renders API doc, the trait params are shown as queryParameters for POST requests instead of multipart/form-data. I was wondering if there’s some notation using which the parameter renders as query and multipart/form-data for GET and POST respectively. Since I’ve more than few such distinct traits, currently, I’m ending up having to define the traits once for GET and once for POST…and this is what I’m trying to avoid/optimize.


#4

It is because it is defined as a queryParameter inside the trait. if you need something else inside your POST, you need to define a new one.