Requiring query params
Published in
1 min readJun 6, 2018
Sometimes we need to require specific query parameters in URLs. There are different ways to go about it in RAML.
Simply required
There is the obvious way:
queryParameters:
foo: string
or the equivalent way:
queryString:
properties:
foo: string
By default, query parameters are required, so simply defining them makes them required.
Either one required
There is a way to require either one of several parameters:
queryString:
type: FooParam | BarParam
with those query parameters previously defined as types:
types:
FooParam:
properties:
foo: string
BarParam:
properties:
bar: number
At least one required
There is a way to require that at least one query parameter is present:
queryParameters:
/^(foo|bar)$/: string
However, the only problem with that definition is that it implies all parameters to be of the same type. So an equivalent way which would allow query parameters to be of different types, would be:
queryString:
minProperties: 1
properties:
foo?: string
bar?: number