raml-org / raml-spec

RAML Specification
http://raml.org
3.86k stars 858 forks source link

RAML : How to require parameter A OR parameter B #680

Open M-Usama44 opened 6 years ago

M-Usama44 commented 6 years ago

I have an issue. i am using raml 1.0. i have two query parameters in my raml so i want to restrict that users should input the value of one parameter atleast. means that if user have entered the value of one parameter then other became optional but BOTH PARAMETERS CAN'T BE EMPTY. from two of them one should be necessary. example PFB the RAML

/abc:
  get:
    queryParameters:
      url:
        type: string
      image:
        type: string

user should give value of url OR image.

jstoiko commented 5 years ago

@M-Usama44: I think you may be better off using queryString instead of queryParameters in this case, and write something like this:

#%RAML 1.0
title: conditional query queryParameters

types:
  option1:
    properties:
      url:
  option2:
    properties:
      image:

/abc:
  get:
    queryString: 
      type: option1 | option2
M-Usama44 commented 5 years ago

The issue doesn't resolve, in your solution if we don't give any parameter the api will response 200 but we want to restrict the user to give at least one parameter. User should have shown two parameters but if he gives anyone of the thenm than the api should run.

ghost commented 5 years ago

@jstoiko I have the exact same with when using RAML 1.0 with MuleSoft software. QueryString doesn't do anything. Just like @M-Usama44 says, it just gives you back a 200 response. Maybe it has to do with the parser or whatsoever, but it is extremely unclear (also in the doc) what the difference is between QueryParams and QueryString (when it comes to RAML arguments).